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
54d31215aa155e01062e00bbfbae8cad8ea45826
bb31430994044506fa42fd667e2d556327e18dfe
/test/ring_exp.lean
2485f20493a065070e7b489b2b0ba272dbf326da
[ "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
7,243
lean
import tactic.ring_exp import tactic.zify import algebra.group_with_zero.power import algebra.ring.pi import tactic.field_simp universes u section addition /-! ### `addition` section Test associativity and commutativity of `(+)`. -/ example (a b : ℚ) : a = a := by ring_exp example (a b : ℚ) : a + b = a + b := by ring_exp example (a b : ℚ) : b + a = a + b := by ring_exp example (a b : ℤ) : a + b + b = b + (a + b) := by ring_exp example (a b c : ℕ) : a + b + b + (c + c) = c + (b + c) + (a + b) := by ring_exp end addition section numerals /-! ### `numerals` section Test that numerals behave like rational numbers. -/ example (a : ℕ) : a + 5 + 5 = 0 + a + 10 := by ring_exp example (a : ℤ) : a + 5 + 5 = 0 + a + 10 := by ring_exp example (a : ℚ) : (1/2) * a + (1/2) * a = a := by ring_exp end numerals section multiplication /-! ### `multiplication section` Test that multiplication is associative and commutative. Also test distributivity of `(+)` and `(*)`. -/ example (a : ℕ) : 0 = a * 0 := by ring_exp_eq example (a : ℕ) : a = a * 1 := by ring_exp example (a : ℕ) : a + a = a * 2 := by ring_exp example (a b : ℤ) : a * b = b * a := by ring_exp example (a b : ℕ) : a * 4 * b + a = a * (4 * b + 1) := by ring_exp end multiplication section exponentiation /-! ### `exponentiation` section Test that exponentiation has the correct distributivity properties. -/ example : 0 ^ 1 = 0 := by ring_exp example : 0 ^ 2 = 0 := by ring_exp example (a : ℕ) : a ^ 0 = 1 := by ring_exp example (a : ℕ) : a ^ 1 = a := by ring_exp example (a : ℕ) : a ^ 2 = a * a := by ring_exp example (a b : ℕ) : a ^ b = a ^ b := by ring_exp example (a b : ℕ) : a ^ (b + 1) = a * a ^ b := by ring_exp example (n : ℕ) (a m : ℕ) : a * a^n * m = a^(n+1) * m := by ring_exp example (n : ℕ) (a m : ℕ) : m * a^n * a = a^(n+1) * m := by ring_exp example (n : ℕ) (a m : ℤ) : a * a^n * m = a^(n+1) * m := by ring_exp example (n : ℕ) (m : ℤ) : 2 * 2^n * m = 2^(n+1) * m := by ring_exp example (n : ℕ) (m : ℤ) : 2^(n+1) * m = 2 * 2^n * m := by ring_exp example (n m : ℕ) (a : ℤ) : (a ^ n)^m = a^(n * m) := by ring_exp example (n m : ℕ) (a : ℤ) : a^(n^0) = a^1 := by ring_exp example (n : ℕ) : 0^(n + 1) = 0 := by ring_exp example {α} [comm_ring α] (x : α) (k : ℕ) : x ^ (k + 2) = x * x * x^k := by ring_exp example {α} [comm_ring α] (k : ℕ) (x y z : α) : x * (z * (x - y)) + (x * (y * y ^ k) - y * (y * y ^ k)) = (z * x + y * y ^ k) * (x - y) := by ring_exp -- We can represent a large exponent `n` more efficiently than just `n` multiplications: example (a b : ℚ) : (a * b) ^ 1000000 = (b * a) ^ 1000000 := by ring_exp example (n : ℕ) : 2 ^ (n + 1 + 1) = 2 * 2 ^ (n + 1) := by ring_exp_eq -- power does not have to be a syntactic match to `monoid.has_pow` example {α} [comm_ring α] (x : ℕ → α) : (x ^ 2 * x) = x ^ 3 := by ring_exp end exponentiation section power_of_sum /-! ### `power_of_sum` section Test that raising a sum to a power behaves like repeated multiplication, if needed. -/ example (a b : ℤ) : (a + b)^2 = a^2 + b^2 + a * b + b * a := by ring_exp example (a b : ℤ) (n : ℕ) : (a + b)^(n + 2) = (a^2 + b^2 + a * b + b * a) * (a + b)^n := by ring_exp end power_of_sum section negation /-! ### `negation` section Test that negation and subtraction satisfy the expected properties, also in semirings such as `ℕ`. -/ example {α} [comm_ring α] (a : α) : a - a = 0 := by ring_exp_eq example (a : ℤ) : a - a = 0 := by ring_exp example (a : ℤ) : a + - a = 0 := by ring_exp example (a : ℤ) : - a = (-1) * a := by ring_exp -- Here, (a - b) is treated as an atom. example (a b : ℕ) : a - b + a + a = a - b + 2 * a := by ring_exp example (n : ℕ) : n + 1 - 1 = n := by ring_exp! -- But we can force a bit of evaluation anyway. end negation constant f {α} : α → α section complicated /-! ### `complicated` section Test that complicated, real-life expressions also get normalized. -/ example {α : Type} [linear_ordered_field α] (x : α) : 2 * x + 1 * 1 - (2 * f (x + 1 / 2) + 2 * 1) + (1 * 1 - (2 * x - 2 * f (x + 1 / 2))) = 0 := by ring_exp_eq example {α : Type u} [linear_ordered_field α] (x : α) : f (x + 1 / 2) ^ 1 * -2 + (f (x + 1 / 2) ^ 1 * 2 + 0) = 0 := by ring_exp_eq example (x y : ℕ) : x + id y = y + id x := by ring_exp! -- Here, we check that `n - s` is not treated as `n + additive_inverse s`, -- if `s` doesn't have an additive inverse. example (B s n : ℕ) : B * (f s * ((n - s) * f (n - s - 1))) = B * (n - s) * (f s * f (n - s - 1)) := by ring_exp -- This is a somewhat subtle case: `-c/b` is parsed as `(-c)/b`, -- so we can't simply treat both sides of the division as atoms. -- Instead, we follow the `ring` tactic in interpreting `-c / b` as `-c * b⁻¹`, -- with only `b⁻¹` an atom. example {α} [linear_ordered_field α] (a b c : α) : a*(-c/b)*(-c/b) = a*((c/b)*(c/b)) := by ring_exp -- test that `field_simp` works fine with powers and `ring_exp`. example (x y : ℚ) (n : ℕ) (hx : x ≠ 0) (hy : y ≠ 0) : 1/ (2/(x / y))^(2 * n) + y / y^(n+1) - (x/y)^n * (x/(2 * y))^n / 2 ^n = 1/y^n := begin field_simp, ring_exp end end complicated -- Test that `nat.succ d` gets handled as `d + 1`. example (d : ℕ) : 2 * (2 ^ d - 1) + 1 = 2 ^ d.succ - 1 := begin zify [nat.one_le_pow'], ring_exp, end -- Simplified instance of a bug reported by Patrick Massot: -- https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/ring_exp.20bug example (l : ℤ) : l - l = 0 := begin tactic.replace_at (tactic.ring_exp.normalize tactic.transparency.reducible) [] tt >> pure (), refl end -- Normalizing also works on more complicated expressions: example (a b : ℤ) : (a^2 - b - b) + (2 * id b - a^2) = 0 := begin tactic.replace_at (tactic.ring_exp.normalize tactic.transparency.semireducible) [] tt >> pure (), refl end section conv /-! ### `conv` section Test that `ring_exp` works inside of `conv`, both with and without `!`. -/ example (n : ℕ) : (2^n * 2 + 1)^10 = (2^(n+1) + 1)^10 := begin conv_rhs { congr, ring_exp, }, conv_lhs { congr, ring_exp, }, end example (x y : ℤ) : x + id y - y + id x = x * 2 := begin conv_lhs { ring_exp!, }, end end conv section benchmark /-! ### `benchmark` section The `ring_exp` tactic shouldn't be too slow. -/ -- This last example was copied from `data/polynomial.lean`, because it timed out. -- After some optimization, it doesn't. variables {α : Type} [comm_ring α] def pow_sub_pow_factor (x y : α) : Π {i : ℕ},{z // x^i - y^i = z*(x - y)} | 0 := ⟨0, by simp⟩ | 1 := ⟨1, by simp⟩ | (k+2) := begin cases @pow_sub_pow_factor (k+1) with z hz, existsi z*x + y^(k+1), rw [pow_succ x, pow_succ y, ←sub_add_sub_cancel (x*x^(k+1)) (x*y^(k+1)), ←mul_sub x, hz], ring_exp_eq end -- Another benchmark: bound the growth of the complexity somewhat. example {α} [comm_semiring α] (x : α) : (x + 1) ^ 4 = (1 + x) ^ 4 := by try_for 5000 {ring_exp} example {α} [comm_semiring α] (x : α) : (x + 1) ^ 6 = (1 + x) ^ 6 := by try_for 10000 {ring_exp} example {α} [comm_semiring α] (x : α) : (x + 1) ^ 8 = (1 + x) ^ 8 := by try_for 15000 {ring_exp} end benchmark
83db70f5926879c3105c5156e946a4623fcf477c
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/tactic/doc_commands.lean
c9fa0b17207383c6ad933a5697784825301a2924
[]
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
9,055
lean
/- Copyright (c) 2020 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.tactic.fix_reflect_string import Mathlib.PostPort universes l namespace Mathlib /-! # Documentation commands We generate html documentation from mathlib. It is convenient to collect lists of tactics, commands, notes, etc. To facilitate this, we declare these documentation entries in the library using special commands. * `library_note` adds a note describing a certain feature or design decision. These can be referenced in doc strings with the text `note [name of note]`. * `add_tactic_doc` adds an entry documenting an interactive tactic, command, hole command, or attribute. Since these commands are used in files imported by `tactic.core`, this file has no imports. ## Implementation details `library_note note_id note_msg` creates a declaration `` `library_note.i `` for some `i`. This declaration is a pair of strings `note_id` and `note_msg`, and it gets tagged with the `library_note` attribute. Similarly, `add_tactic_doc` creates a declaration `` `tactic_doc.i `` that stores the provided information. -/ /-- A rudimentary hash function on strings. -/ def string.hash (s : string) : ℕ := string.fold 1 (fun (h : ℕ) (c : char) => (bit1 (bit0 (bit0 (bit0 (bit0 1)))) * h + char.val c) % unsigned_sz) s /-- `mk_hashed_name nspace id` hashes the string `id` to a value `i` and returns the name `nspace._i` -/ /-- `copy_doc_string fr to` copies the docstring from the declaration named `fr` to each declaration named in the list `to`. -/ /-- `copy_doc_string source → target_1 target_2 ... target_n` copies the doc string of the declaration named `source` to each of `target_1`, `target_2`, ..., `target_n`. -/ /-! ### The `library_note` command -/ /-- A user attribute `library_note` for tagging decls of type `string × string` for use in note output. -/ /-- `mk_reflected_definition name val` constructs a definition declaration by reflection. Example: ``mk_reflected_definition `foo 17`` constructs the definition declaration corresponding to `def foo : ℕ := 17` -/ /-- If `note_name` and `note` are `pexpr`s representing strings, `add_library_note note_name note` adds a declaration of type `string × string` and tags it with the `library_note` attribute. -/ /-- A command to add library notes. Syntax: ``` /-- note message -/ /-- Collects all notes in the current environment. Returns a list of pairs `(note_id, note_content)` -/ /-! ### The `add_tactic_doc_entry` command -/ /-- The categories of tactic doc entry. -/ inductive doc_category where | tactic : doc_category | cmd : doc_category | hole_cmd : doc_category | attr : doc_category /-- Format a `doc_category` -/ /-- The information used to generate a tactic doc entry -/ structure tactic_doc_entry where name : string category : doc_category decl_names : List name tags : List string description : string inherit_description_from : Option name /-- Turns a `tactic_doc_entry` into a JSON representation. -/ /-- `update_description_from tde inh_id` replaces the `description` field of `tde` with the doc string of the declaration named `inh_id`. -/ /-- `update_description tde` replaces the `description` field of `tde` with: * the doc string of `tde.inherit_description_from`, if this field has a value * the doc string of the entry in `tde.decl_names`, if this field has length 1 If neither of these conditions are met, it returns `tde`. -/ /-- A user attribute `tactic_doc` for tagging decls of type `tactic_doc_entry` for use in doc output -/ /-- Collects everything in the environment tagged with the attribute `tactic_doc`. -/ /-- `add_tactic_doc tde` adds a declaration to the environment with `tde` as its body and tags it with the `tactic_doc` attribute. If `tde.decl_names` has exactly one entry `` `decl`` and if `tde.description` is the empty string, `add_tactic_doc` uses the doc string of `decl` as the description. -/ /-- A command used to add documentation for a tactic, command, hole command, or attribute. Usage: after defining an interactive tactic, command, or attribute, add its documentation as follows. ```lean /-- describe what the command does here -/ /-- At various places in mathlib, we leave implementation notes that are referenced from many other files. To keep track of these notes, we use the command `library_note`. This makes it easy to retrieve a list of all notes, e.g. for documentation output. These notes can be referenced in mathlib with the syntax `Note [note id]`. Often, these references will be made in code comments (`--`) that won't be displayed in docs. If such a reference is made in a doc string or module doc, it will be linked to the corresponding note in the doc display. Syntax: ``` /-- note message -/ /-- Some declarations work with open expressions, i.e. an expr that has free variables. Terms will free variables are not well-typed, and one should not use them in tactics like `infer_type` or `unify`. You can still do syntactic analysis/manipulation on them. The reason for working with open types is for performance: instantiating variables requires iterating through the expression. In one performance test `pi_binders` was more than 6x quicker than `mk_local_pis` (when applied to the type of all imported declarations 100x). -/ -- See Note [open expressions] /-- behavior of f -/ -- add docs to core tactics /-- The congruence closure tactic `cc` tries to solve the goal by chaining equalities from context and applying congruence (i.e. if `a = b`, then `f a = f b`). It is a finishing tactic, i.e. it is meant to close the current goal, not to make some inconclusive progress. A mostly trivial example would be: ```lean example (a b c : ℕ) (f : ℕ → ℕ) (h: a = b) (h' : b = c) : f a = f c := by cc ``` As an example requiring some thinking to do by hand, consider: ```lean example (f : ℕ → ℕ) (x : ℕ) (H1 : f (f (f x)) = x) (H2 : f (f (f (f (f x)))) = x) : f x = x := by cc ``` The tactic works by building an equality matching graph. It's a graph where the vertices are terms and they are linked by edges if they are known to be equal. Once you've added all the equalities in your context, you take the transitive closure of the graph and, for each connected component (i.e. equivalence class) you can elect a term that will represent the whole class and store proofs that the other elements are equal to it. You then take the transitive closure of these equalities under the congruence lemmas. The `cc` implementation in Lean does a few more tricks: for example it derives `a=b` from `nat.succ a = nat.succ b`, and `nat.succ a != nat.zero` for any `a`. * The starting reference point is Nelson, Oppen, [Fast decision procedures based on congruence closure](http://www.cs.colorado.edu/~bec/courses/csci5535-s09/reading/nelson-oppen-congruence.pdf), Journal of the ACM (1980) * The congruence lemmas for dependent type theory as used in Lean are described in [Congruence closure in intensional type theory](https://leanprover.github.io/papers/congr.pdf) (de Moura, Selsam IJCAR 2016). -/ /-- `conv {...}` allows the user to perform targeted rewriting on a goal or hypothesis, by focusing on particular subexpressions. See <https://leanprover-community.github.io/extras/conv.html> for more details. Inside `conv` blocks, mathlib currently additionally provides * `erw`, * `ring`, `ring2` and `ring_exp`, * `norm_num`, * `norm_cast`, * `apply_congr`, and * `conv` (within another `conv`). `apply_congr` applies congruence lemmas to step further inside expressions, and sometimes gives between results than the automatically generated congruence lemmas used by `congr`. Using `conv` inside a `conv` block allows the user to return to the previous state of the outer `conv` block after it is finished. Thus you can continue editing an expression without having to start a new `conv` block and re-scoping everything. For example: ```lean example (a b c d : ℕ) (h₁ : b = c) (h₂ : a + c = a + d) : a + b = a + d := by conv { to_lhs, conv { congr, skip, rw h₁, }, rw h₂, } ``` Without `conv`, the above example would need to be proved using two successive `conv` blocks, each beginning with `to_lhs`. Also, as a shorthand, `conv_lhs` and `conv_rhs` are provided, so that ```lean example : 0 + 0 = 0 := begin conv_lhs { simp } end ``` just means ```lean example : 0 + 0 = 0 := begin conv { to_lhs, simp } end ``` and likewise for `to_rhs`. -/ /-- Accepts terms with the type `component tactic_state string` or `html empty` and renders them interactively. Requires a compatible version of the vscode extension to view the resulting widget. ### Example: ```lean /-- A simple counter that can be incremented or decremented with some buttons. -/ /-- The `add_decl_doc` command is used to add a doc string to an existing declaration. ```lean def foo := 5 /-- Doc string for foo. -/
7a42ecbfc15b854d01f4d118847b4733d94d75b6
f5f7e6fae601a5fe3cac7cc3ed353ed781d62419
/src/ring_theory/adjoin_root.lean
fba4dc7cf477c6b9dfe25cb2a1e0923e267e0004
[ "Apache-2.0" ]
permissive
EdAyers/mathlib
9ecfb2f14bd6caad748b64c9c131befbff0fb4e0
ca5d4c1f16f9c451cf7170b10105d0051db79e1b
refs/heads/master
1,626,189,395,845
1,555,284,396,000
1,555,284,396,000
144,004,030
0
0
Apache-2.0
1,533,727,664,000
1,533,727,663,000
null
UTF-8
Lean
false
false
3,657
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 Adjoining roots of polynomials -/ import data.polynomial ring_theory.principal_ideal_domain universes u v w variables {α : Type u} {β : Type v} {γ : Type w} namespace adjoin_root open polynomial ideal section comm_ring variables [comm_ring α] [decidable_eq α] (f : polynomial α) def adjoin_root (f : polynomial α) : Type u := ideal.quotient (span {f} : ideal (polynomial α)) instance : comm_ring (adjoin_root f) := ideal.quotient.comm_ring _ noncomputable instance : decidable_eq (adjoin_root f) := classical.dec_eq _ variable {f} def mk : polynomial α → adjoin_root f := ideal.quotient.mk _ def root : adjoin_root f := mk X def of (x : α) : adjoin_root f := mk (C x) instance adjoin_root.has_coe_t : has_coe_t α (adjoin_root f) := ⟨of⟩ instance mk.is_ring_hom : is_ring_hom (mk : polynomial α → adjoin_root f) := ideal.quotient.is_ring_hom_mk _ @[simp] lemma mk_self : (mk f : adjoin_root f) = 0 := quotient.sound' (mem_span_singleton.2 $ by simp) instance : is_ring_hom (coe : α → adjoin_root f) := @is_ring_hom.comp _ _ _ _ C _ _ _ mk mk.is_ring_hom lemma eval₂_root (f : polynomial α) : f.eval₂ coe (root : adjoin_root f) = 0 := quotient.induction_on' (root : adjoin_root f) (λ (g : polynomial α) (hg : mk g = mk X), show finsupp.sum f (λ (e : ℕ) (a : α), mk (C a) * mk g ^ e) = 0, by simp only [hg, (is_semiring_hom.map_pow (mk : polynomial α → adjoin_root f) _ _).symm, (is_ring_hom.map_mul (mk : polynomial α → adjoin_root f)).symm]; rw [finsupp.sum, finset.sum_hom (mk : polynomial α → adjoin_root f), show finset.sum _ _ = _, from sum_C_mul_X_eq _, mk_self]) (show (root : adjoin_root f) = mk X, from rfl) lemma is_root_root (f : polynomial α) : is_root (f.map coe) (root : adjoin_root f) := by rw [is_root, eval_map, eval₂_root] variables [comm_ring β] def lift (i : α → β) [is_ring_hom i] (x : β) (h : f.eval₂ i x = 0) : (adjoin_root f) → β := ideal.quotient.lift _ (eval₂ i x) $ λ g H, begin simp [mem_span_singleton] at H, cases H with y H, dsimp at H, rw [H, eval₂_mul], simp [h] end variables {i : α → β} [is_ring_hom i] {a : β} {h : f.eval₂ i a = 0} @[simp] lemma lift_mk {g : polynomial α} : lift i a h (mk g) = g.eval₂ i a := ideal.quotient.lift_mk @[simp] lemma lift_root : lift i a h root = a := by simp [root, h] @[simp] lemma lift_of {x : α} : lift i a h x = i x := by show lift i a h (ideal.quotient.mk _ (C x)) = i x; convert ideal.quotient.lift_mk; simp instance is_ring_hom_lift : is_ring_hom (lift i a h) := by unfold lift; apply_instance end comm_ring variables [discrete_field α] {f : polynomial α} [irreducible f] instance is_maximal_span : is_maximal (span {f} : ideal (polynomial α)) := principal_ideal_domain.is_maximal_of_irreducible ‹irreducible f› noncomputable instance field : discrete_field (adjoin_root f) := ideal.quotient.field (span {f} : ideal (polynomial α)) instance : is_field_hom (coe : α → adjoin_root f) := by apply_instance instance lift_is_field_hom [field β] {i : α → β} [is_ring_hom i] {a : β} {h : f.eval₂ i a = 0} : is_field_hom (lift i a h) := by apply_instance lemma coe_injective : function.injective (coe : α → adjoin_root f) := is_field_hom.injective _ lemma mul_div_root_cancel (f : polynomial α) [irreducible f] : (X - C (root : adjoin_root f)) * (f.map coe / (X - C root)) = f.map coe := mul_div_eq_iff_is_root.2 $ is_root_root _ end adjoin_root
0ea7648e16bbd93af02ba900ccb5e9f1873d3c93
acc85b4be2c618b11fc7cb3005521ae6858a8d07
/data/list/sort.lean
a20c6122b1edf243f2d074d5ce1e15b95212d035
[ "Apache-2.0" ]
permissive
linpingchuan/mathlib
d49990b236574df2a45d9919ba43c923f693d341
5ad8020f67eb13896a41cc7691d072c9331b1f76
refs/heads/master
1,626,019,377,808
1,508,048,784,000
1,508,048,784,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
9,627
lean
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Jeremy Avigad Insertion sort and merge sort. -/ import data.list.perm open list.perm namespace list section sorted universe variable uu variables {α : Type uu} {r : α → α → Prop} def sorted := @pairwise @[simp] theorem sorted_nil : sorted r [] := pairwise.nil _ @[simp] theorem sorted_singleton (a : α) : sorted r [a] := pairwise_singleton _ _ theorem sorted_of_sorted_cons {a : α} {l : list α} : sorted r (a :: l) → sorted r l := pairwise_of_pairwise_cons theorem rel_of_sorted_cons {a : α} {l : list α} : sorted r (a :: l) → ∀ b ∈ l, r a b := rel_of_pairwise_cons @[simp] theorem sorted_cons {a : α} {l : list α} : sorted r (a :: l) ↔ (∀ b ∈ l, r a b) ∧ sorted r l := pairwise_cons theorem eq_of_sorted_of_perm (tr : transitive r) (anti : anti_symmetric r) {l₁ l₂ : list α} (p : l₁ ~ l₂) (s₁ : sorted r l₁) (s₂ : sorted r l₂) : l₁ = l₂ := begin induction s₁ with a l₁ h₁ s₁ IH generalizing l₂, { rw eq_nil_of_perm_nil p }, { have : a ∈ l₂ := mem_of_perm p (mem_cons_self _ _), rcases mem_split this with ⟨u₂, v₂, e⟩, subst e, have p' := (perm_cons a).1 (p.trans perm_middle), have := IH p' (pairwise_of_sublist (by simp) s₂), subst l₁, change a::u₂ ++ v₂ = u₂ ++ ([a] ++ v₂), rw ← append_assoc, congr, have : ∀ (x : α) (h : x ∈ u₂), x = a := λ x m, anti ((pairwise_append.1 s₂).2.2 _ m a (mem_cons_self _ _)) (h₁ _ (by simp [m])), rw [(@eq_repeat _ a (length u₂ + 1) (a::u₂)).2, (@eq_repeat _ a (length u₂ + 1) (u₂++[a])).2]; split; simp [iff_true_intro this] } end end sorted /- sorting procedures -/ section sort universe variable uu parameters {α : Type uu} (r : α → α → Prop) [decidable_rel r] local infix `≼` : 50 := r /- insertion sort -/ section insertion_sort @[simp] def ordered_insert (a : α) : list α → list α | [] := [a] | (b :: l) := if a ≼ b then a :: b :: l else b :: ordered_insert l @[simp] def insertion_sort : list α → list α | [] := [] | (b :: l) := ordered_insert b (insertion_sort l) section correctness parameter [deceqα : decidable_eq α] include deceqα open perm theorem perm_ordered_insert (a) : ∀ l : list α, ordered_insert a l ~ a :: l | [] := perm.refl _ | (b :: l) := by by_cases a ≼ b; [simp [ordered_insert, h], simpa [ordered_insert, h] using (perm.skip _ (perm_ordered_insert l)).trans (perm.swap _ _ _)] theorem perm_insertion_sort : ∀ l : list α, insertion_sort l ~ l | [] := perm.nil | (b :: l) := by simpa [insertion_sort] using (perm_ordered_insert _ _ _).trans (perm.skip b (perm_insertion_sort l)) section total_and_transitive variables (totr : total r) (transr : transitive r) include totr transr theorem sorted_ordered_insert (a : α) : ∀ l, sorted r l → sorted r (ordered_insert a l) | [] h := sorted_singleton a | (b :: l) h := begin by_cases a ≼ b with h', { simpa [ordered_insert, h', h] using λ b' bm, transr h' (rel_of_sorted_cons h _ bm) }, { suffices : ∀ (b' : α), b' ∈ ordered_insert r a l → r b b', { simpa [ordered_insert, h', sorted_ordered_insert l (sorted_of_sorted_cons h)] }, intros b' bm, cases (show b' = a ∨ b' ∈ l, by simpa using mem_of_perm (perm_ordered_insert _ _ _) bm) with be bm, { subst b', exact (totr _ _).resolve_left h' }, { exact rel_of_sorted_cons h _ bm } } end theorem sorted_insertion_sort : ∀ l, sorted r (insertion_sort l) | [] := sorted_nil | (a :: l) := sorted_ordered_insert totr transr a _ (sorted_insertion_sort l) end total_and_transitive end correctness end insertion_sort /- merge sort -/ section merge_sort -- TODO(Jeremy): observation: if instead we write (a :: (split l).1, b :: (split l).2), the -- equation compiler can't prove the third equation def split : list α → list α × list α | [] := ([], []) | (a :: l) := let (l₁, l₂) := split l in (a :: l₂, l₁) attribute [simp] split theorem split_cons_of_eq (a : α) {l l₁ l₂ : list α} (h : split l = (l₁, l₂)) : split (a :: l) = (a :: l₂, l₁) := by rw [split, h]; refl theorem length_split_le : ∀ {l l₁ l₂ : list α}, split l = (l₁, l₂) → length l₁ ≤ length l ∧ length l₂ ≤ length l | [] ._ ._ rfl := ⟨nat.le_refl 0, nat.le_refl 0⟩ | (a::l) l₁' l₂' h := begin cases e : split l with l₁ l₂, injection (split_cons_of_eq _ e).symm.trans h, substs l₁' l₂', cases length_split_le e with h₁ h₂, exact ⟨nat.succ_le_succ h₂, nat.le_succ_of_le h₁⟩ end theorem length_split_lt {a b} {l l₁ l₂ : list α} (h : split (a::b::l) = (l₁, l₂)) : length l₁ < length (a::b::l) ∧ length l₂ < length (a::b::l) := begin cases e : split l with l₁' l₂', injection (split_cons_of_eq _ (split_cons_of_eq _ e)).symm.trans h, substs l₁ l₂, cases length_split_le e with h₁ h₂, exact ⟨nat.succ_le_succ (nat.succ_le_succ h₁), nat.succ_le_succ (nat.succ_le_succ h₂)⟩ end theorem perm_split : ∀ {l l₁ l₂ : list α}, split l = (l₁, l₂) → l ~ l₁ ++ l₂ | [] ._ ._ rfl := perm.refl _ | (a::l) l₁' l₂' h := begin cases e : split l with l₁ l₂, injection (split_cons_of_eq _ e).symm.trans h, substs l₁' l₂', exact perm.skip a ((perm_split e).trans perm_app_comm), end def merge : list α → list α → list α | [] l' := l' | l [] := l | (a :: l) (b :: l') := if a ≼ b then a :: merge l (b :: l') else b :: merge (a :: l) l' include r def merge_sort : list α → list α | [] := [] | [a] := [a] | (a::b::l) := begin cases e : split (a::b::l) with l₁ l₂, cases length_split_lt e with h₁ h₂, exact merge r (merge_sort l₁) (merge_sort l₂) end using_well_founded { rel_tac := λ_ _, `[exact ⟨_, inv_image.wf length nat.lt_wf⟩], dec_tac := tactic.assumption } theorem merge_sort_cons_cons {a b} {l l₁ l₂ : list α} (h : split (a::b::l) = (l₁, l₂)) : merge_sort (a::b::l) = merge (merge_sort l₁) (merge_sort l₂) := begin suffices : ∀ (L : list α) h1, @@and.rec (λ a a (_ : length l₁ < length l + 1 + 1 ∧ length l₂ < length l + 1 + 1), L) h1 h1 = L, { simp [merge_sort, h], apply this }, intros, cases h1, refl end section correctness parameter [deceqα : decidable_eq α] include deceqα theorem perm_merge : ∀ (l l' : list α), merge l l' ~ l ++ l' | [] [] := perm.nil | [] (b :: l') := by simp [merge] | (a :: l) [] := by simp [merge] | (a :: l) (b :: l') := begin by_cases a ≼ b, { simpa [merge, h] using skip _ (perm_merge _ _) }, { suffices : b :: merge r (a :: l) l' ~ a :: (l ++ b :: l'), {simpa [merge, h]}, exact (skip _ (perm_merge _ _)).trans ((swap _ _ _).trans (skip _ perm_middle.symm)) } end theorem perm_merge_sort : ∀ l : list α, merge_sort l ~ l | [] := perm.refl _ | [a] := perm.refl _ | (a::b::l) := begin cases e : split (a::b::l) with l₁ l₂, cases length_split_lt e with h₁ h₂, rw [merge_sort_cons_cons r e], apply (perm_merge r _ _).trans, exact (perm_app (perm_merge_sort l₁) (perm_merge_sort l₂)).trans (perm_split e).symm end using_well_founded { rel_tac := λ_ _, `[exact ⟨_, inv_image.wf length nat.lt_wf⟩], dec_tac := tactic.assumption } section total_and_transitive variables (totr : total r) (transr : transitive r) include totr transr theorem sorted_merge : ∀ {l l' : list α}, sorted r l → sorted r l' → sorted r (merge l l') | [] [] h₁ h₂ := sorted_nil | [] (b :: l') h₁ h₂ := by simpa [merge] using h₂ | (a :: l) [] h₁ h₂ := by simpa [merge] using h₁ | (a :: l) (b :: l') h₁ h₂ := begin by_cases a ≼ b, { suffices : ∀ (b' : α) (_ : b' ∈ merge r l (b :: l')), r a b', { simpa [merge, h, sorted_merge (sorted_of_sorted_cons h₁) h₂] }, intros b' bm, rcases (show b' = b ∨ b' ∈ l ∨ b' ∈ l', by simpa using mem_of_perm (perm_merge _ _ _) bm) with be | bl | bl', { subst b', assumption }, { exact rel_of_sorted_cons h₁ _ bl }, { exact transr h (rel_of_sorted_cons h₂ _ bl') } }, { suffices : ∀ (b' : α) (_ : b' ∈ merge r (a :: l) l'), r b b', { simpa [merge, h, sorted_merge h₁ (sorted_of_sorted_cons h₂)] }, intros b' bm, have ba : b ≼ a := (totr _ _).resolve_left h, rcases (show b' = a ∨ b' ∈ l ∨ b' ∈ l', by simpa using mem_of_perm (perm_merge _ _ _) bm) with be | bl | bl', { subst b', assumption }, { exact transr ba (rel_of_sorted_cons h₁ _ bl) }, { exact rel_of_sorted_cons h₂ _ bl' } } end theorem sorted_merge_sort : ∀ l : list α, sorted r (merge_sort l) | [] := sorted_nil | [a] := sorted_singleton _ | (a::b::l) := begin cases e : split (a::b::l) with l₁ l₂, cases length_split_lt e with h₁ h₂, rw [merge_sort_cons_cons r e], exact sorted_merge r totr transr (sorted_merge_sort l₁) (sorted_merge_sort l₂) end using_well_founded { rel_tac := λ_ _, `[exact ⟨_, inv_image.wf length nat.lt_wf⟩], dec_tac := tactic.assumption } end total_and_transitive end correctness end merge_sort end sort /- try them out! -/ --#eval insertion_sort (λ m n : ℕ, m ≤ n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12] --#eval merge_sort (λ m n : ℕ, m ≤ n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12] end list
e56637a80264dfbe86bc3d2067a1b614b451fd7d
86f6f4f8d827a196a32bfc646234b73328aeb306
/examples/basics/unnamed_1473.lean
b5a304bfb8484e5cb36fd3f4eae262ba7489b3e8
[]
no_license
jamescheuk91/mathematics_in_lean
09f1f87d2b0dce53464ff0cbe592c568ff59cf5e
4452499264e2975bca2f42565c0925506ba5dda3
refs/heads/master
1,679,716,410,967
1,613,957,947,000
1,613,957,947,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
323
lean
import data.real.basic variables a b : ℝ -- BEGIN example : min a b = min b a := begin apply le_antisymm, { show min a b ≤ min b a, apply le_min, { apply min_le_right }, apply min_le_left }, { show min b a ≤ min a b, apply le_min, { apply min_le_right }, apply min_le_left } end -- END
f52549e4ce1c402559312a4b2c11bdbc8a6880c3
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/data/list/rdrop.lean
be776a052459164a31b39a361c0727468a88d8ba
[ "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
6,896
lean
/- Copyright (c) 2022 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import data.list.basic import data.list.infix /-! # Dropping or taking from lists on the right Taking or removing element from the tail end of a list ## Main defintions - `rdrop n`: drop `n : ℕ` elements from the tail - `rtake n`: take `n : ℕ` elements from the tail - `drop_while p`: remove all the elements that satisfy a decidable `p : α → Prop` from the tail of a list until hitting the first non-satisfying element - `take_while p`: take all the elements that satisfy a decidable `p : α → Prop` from the tail of a list until hitting the first non-satisfying element ## Implementation detail The two predicate-based methods operate by performing the regular "from-left" operation on `list.reverse`, followed by another `list.reverse`, so they are not the most performant. The other two rely on `list.length l` so they still traverse the list twice. One could construct another function that takes a `L : ℕ` and use `L - n`. Under a proof condition that `L = l.length`, the function would do the right thing. -/ variables {α : Type*} (p : α → Prop) [decidable_pred p] (l : list α) (n : ℕ) namespace list /-- Drop `n` elements from the tail end of a list. -/ def rdrop : list α := l.take (l.length - n) @[simp] lemma rdrop_nil : rdrop ([] : list α) n = [] := by simp [rdrop] @[simp] lemma rdrop_zero : rdrop l 0 = l := by simp [rdrop] lemma rdrop_eq_reverse_drop_reverse : l.rdrop n = reverse (l.reverse.drop n) := begin rw rdrop, induction l using list.reverse_rec_on with xs x IH generalizing n, { simp }, { cases n, { simp [take_append] }, { simp [take_append_eq_append_take, IH] } } end @[simp] lemma rdrop_concat_succ (x : α) : rdrop (l ++ [x]) (n + 1) = rdrop l n := by simp [rdrop_eq_reverse_drop_reverse] /-- Take `n` elements from the tail end of a list. -/ def rtake : list α := l.drop (l.length - n) @[simp] lemma rtake_nil : rtake ([] : list α) n = [] := by simp [rtake] @[simp] lemma rtake_zero : rtake l 0 = [] := by simp [rtake] lemma rtake_eq_reverse_take_reverse : l.rtake n = reverse (l.reverse.take n) := begin rw rtake, induction l using list.reverse_rec_on with xs x IH generalizing n, { simp }, { cases n, { simp }, { simp [drop_append_eq_append_drop, IH] } } end @[simp] lemma rtake_concat_succ (x : α) : rtake (l ++ [x]) (n + 1) = rtake l n ++ [x] := by simp [rtake_eq_reverse_take_reverse] /-- Drop elements from the tail end of a list that satisfy `p : α → Prop`. Implemented naively via `list.reverse` -/ def rdrop_while : list α := reverse (l.reverse.drop_while p) @[simp] lemma rdrop_while_nil : rdrop_while p ([] : list α) = [] := by simp [rdrop_while, drop_while] lemma rdrop_while_concat (x : α) : rdrop_while p (l ++ [x]) = if p x then rdrop_while p l else l ++ [x] := begin simp only [rdrop_while, drop_while, reverse_append, reverse_singleton, singleton_append], split_ifs with h h; simp [h] end @[simp] lemma rdrop_while_concat_pos (x : α) (h : p x) : rdrop_while p (l ++ [x]) = rdrop_while p l := by rw [rdrop_while_concat, if_pos h] @[simp] lemma rdrop_while_concat_neg (x : α) (h : ¬ p x) : rdrop_while p (l ++ [x]) = l ++ [x] := by rw [rdrop_while_concat, if_neg h] lemma rdrop_while_singleton (x : α) : rdrop_while p [x] = if p x then [] else [x] := by rw [←nil_append [x], rdrop_while_concat, rdrop_while_nil] lemma rdrop_while_last_not (hl : (l.rdrop_while p) ≠ []): ¬ p ((rdrop_while p l).last hl) := begin simp_rw rdrop_while, rw last_reverse, exact drop_while_nth_le_zero_not _ _ _ end lemma rdrop_while_prefix : l.rdrop_while p <+: l := begin rw [←reverse_suffix, rdrop_while, reverse_reverse], exact drop_while_suffix _ end variables {p} {l} @[simp] lemma rdrop_while_eq_nil_iff : rdrop_while p l = [] ↔ ∀ x ∈ l, p x := by simp [rdrop_while] -- it is in this file because it requires `list.infix` @[simp] lemma drop_while_eq_self_iff : drop_while p l = l ↔ ∀ (hl : 0 < l.length), ¬ p (l.nth_le 0 hl) := begin induction l with hd tl IH, { simp }, { rw drop_while, split_ifs, { simp only [h, length, nth_le, nat.succ_pos', not_true, forall_true_left, iff_false], intro H, refine (cons_ne_self hd tl) (sublist.antisymm _ (sublist_cons _ _)), rw ←H, exact (drop_while_suffix _).sublist }, { simp [h] } } end @[simp] lemma rdrop_while_eq_self_iff : rdrop_while p l = l ↔ ∀ (hl : l ≠ []), ¬ p (l.last hl) := begin simp only [rdrop_while, reverse_eq_iff, length_reverse, ne.def, drop_while_eq_self_iff, last_eq_nth_le, ←length_eq_zero, pos_iff_ne_zero], refine forall_congr _, intro h, rw [nth_le_reverse'], { simp }, { rw [←ne.def, ←pos_iff_ne_zero] at h, simp [tsub_lt_iff_right (nat.succ_le_of_lt h)] } end variables (p) (l) lemma drop_while_idempotent : drop_while p (drop_while p l) = drop_while p l := drop_while_eq_self_iff.mpr (drop_while_nth_le_zero_not _ _) lemma rdrop_while_idempotent : rdrop_while p (rdrop_while p l) = rdrop_while p l := rdrop_while_eq_self_iff.mpr (rdrop_while_last_not _ _) /-- Take elements from the tail end of a list that satisfy `p : α → Prop`. Implemented naively via `list.reverse` -/ def rtake_while : list α := reverse (l.reverse.take_while p) @[simp] lemma rtake_while_nil : rtake_while p ([] : list α) = [] := by simp [rtake_while, take_while] lemma rtake_while_concat (x : α) : rtake_while p (l ++ [x]) = if p x then rtake_while p l ++ [x] else [] := begin simp only [rtake_while, take_while, reverse_append, reverse_singleton, singleton_append], split_ifs with h h; simp [h] end @[simp] lemma rtake_while_concat_pos (x : α) (h : p x) : rtake_while p (l ++ [x]) = rtake_while p l ++ [x] := by rw [rtake_while_concat, if_pos h] @[simp] lemma rtake_while_concat_neg (x : α) (h : ¬ p x) : rtake_while p (l ++ [x]) = [] := by rw [rtake_while_concat, if_neg h] lemma rtake_while_suffix : l.rtake_while p <:+ l := begin rw [←reverse_prefix, rtake_while, reverse_reverse], exact take_while_prefix _ end variables {p} {l} @[simp] lemma rtake_while_eq_self_iff : rtake_while p l = l ↔ ∀ x ∈ l, p x := by simp [rtake_while, reverse_eq_iff] @[simp] lemma rtake_while_eq_nil_iff : rtake_while p l = [] ↔ ∀ (hl : l ≠ []), ¬ p (l.last hl) := begin induction l using list.reverse_rec_on; simp [rtake_while] end lemma mem_rtake_while_imp {x : α} (hx : x ∈ rtake_while p l) : p x := begin suffices : x ∈ take_while p l.reverse, { exact mem_take_while_imp this }, rwa [←mem_reverse, ←rtake_while] end variables (p) (l) lemma rtake_while_idempotent : rtake_while p (rtake_while p l) = rtake_while p l := rtake_while_eq_self_iff.mpr (λ _, mem_rtake_while_imp) end list
36647a75f7c569aff3fd1ee36219e6d6771b6875
3d2a7f1582fe5bae4d0bdc2fe86e997521239a65
/spatial-reasoning/spatial-reasoning-problem-16.lean
25181d034781804349fe89bbd4298dac75b8c94e
[]
no_license
own-pt/common-sense-lean
e4fa643ae010459de3d1bf673be7cbc7062563c9
f672210aecb4172f5bae265e43e6867397e13b1c
refs/heads/master
1,622,065,660,261
1,589,487,533,000
1,589,487,533,000
254,167,782
3
2
null
1,589,487,535,000
1,586,370,214,000
Lean
UTF-8
Lean
false
false
315
lean
/- Spatial Reasoning Problem 16 -/ /- It can be found at: SpatialQs.txt -/ /- (16) Jane is looking at Mark and John. Mark is to the left of John from her perspective. Mary is also looking at Mark and John and Mark appears to the right of John from her perspective. Is John in between Mary and Jane? -/
daedf0548920c50bcf6132ecadca9b0154011d22
a45212b1526d532e6e83c44ddca6a05795113ddc
/src/data/equiv/list.lean
499ce6d1987abbb2e9fb82ae8df3d8be4cc7830e
[ "Apache-2.0" ]
permissive
fpvandoorn/mathlib
b21ab4068db079cbb8590b58fda9cc4bc1f35df4
b3433a51ea8bc07c4159c1073838fc0ee9b8f227
refs/heads/master
1,624,791,089,608
1,556,715,231,000
1,556,715,231,000
165,722,980
5
0
Apache-2.0
1,552,657,455,000
1,547,494,646,000
Lean
UTF-8
Lean
false
false
8,919
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Mario Carneiro Additional equiv and encodable instances for lists and finsets. -/ import data.equiv.denumerable data.nat.pairing order.order_iso data.array.lemmas data.fintype open nat list namespace encodable variables {α : Type*} section list variable [encodable α] def encode_list : list α → ℕ | [] := 0 | (a::l) := succ (mkpair (encode a) (encode_list l)) def decode_list : ℕ → option (list α) | 0 := some [] | (succ v) := match unpair v, unpair_le_right v with | (v₁, v₂), h := have v₂ < succ v, from lt_succ_of_le h, (::) <$> decode α v₁ <*> decode_list v₂ end instance list : encodable (list α) := ⟨encode_list, decode_list, λ l, by induction l with a l IH; simp [encode_list, decode_list, unpair_mkpair, encodek, *]⟩ @[simp] theorem encode_list_nil : encode (@nil α) = 0 := rfl @[simp] theorem encode_list_cons (a : α) (l : list α) : encode (a :: l) = succ (mkpair (encode a) (encode l)) := rfl @[simp] theorem decode_list_zero : decode (list α) 0 = some [] := rfl @[simp] theorem decode_list_succ (v : ℕ) : decode (list α) (succ v) = (::) <$> decode α v.unpair.1 <*> decode (list α) v.unpair.2 := show decode_list (succ v) = _, begin cases e : unpair v with v₁ v₂, simp [decode_list, e], refl end theorem length_le_encode : ∀ (l : list α), length l ≤ encode l | [] := _root_.zero_le _ | (a :: l) := succ_le_succ $ le_trans (length_le_encode l) (le_mkpair_right _ _) end list section finset variables [encodable α] private def enle : α → α → Prop := encode ⁻¹'o (≤) private lemma enle.is_linear_order : is_linear_order α enle := (order_embedding.preimage ⟨encode, encode_injective⟩ (≤)).is_linear_order private def decidable_enle (a b : α) : decidable (enle a b) := by unfold enle order.preimage; apply_instance local attribute [instance] enle.is_linear_order decidable_enle def encode_multiset (s : multiset α) : ℕ := encode (s.sort enle) def decode_multiset (n : ℕ) : option (multiset α) := coe <$> decode (list α) n instance multiset : encodable (multiset α) := ⟨encode_multiset, decode_multiset, λ s, by simp [encode_multiset, decode_multiset, encodek]⟩ end finset def encodable_of_list [decidable_eq α] (l : list α) (H : ∀ x, x ∈ l) : encodable α := ⟨λ a, index_of a l, l.nth, λ a, index_of_nth (H _)⟩ def trunc_encodable_of_fintype (α : Type*) [decidable_eq α] [fintype α] : trunc (encodable α) := @@quot.rec_on_subsingleton _ (λ s : multiset α, (∀ x:α, x ∈ s) → trunc (encodable α)) _ finset.univ.1 (λ l H, trunc.mk $ encodable_of_list l H) finset.mem_univ instance vector [encodable α] {n} : encodable (vector α n) := encodable.subtype instance fin_arrow [encodable α] {n} : encodable (fin n → α) := of_equiv _ (equiv.vector_equiv_fin _ _).symm instance fin_pi (n) (π : fin n → Type*) [∀i, encodable (π i)] : encodable (Πi, π i) := of_equiv _ (equiv.pi_equiv_subtype_sigma (fin n) π) instance array [encodable α] {n} : encodable (array n α) := of_equiv _ (equiv.array_equiv_fin _ _) instance finset [encodable α] : encodable (finset α) := by haveI := decidable_eq_of_encodable α; exact of_equiv {s : multiset α // s.nodup} ⟨λ ⟨a, b⟩, ⟨a, b⟩, λ⟨a, b⟩, ⟨a, b⟩, λ ⟨a, b⟩, rfl, λ⟨a, b⟩, rfl⟩ def fintype_arrow (α : Type*) (β : Type*) [fintype α] [decidable_eq α] [encodable β] : trunc (encodable (α → β)) := (fintype.equiv_fin α).map $ λf, encodable.of_equiv (fin (fintype.card α) → β) $ equiv.arrow_congr f (equiv.refl _) def fintype_pi (α : Type*) (π : α → Type*) [fintype α] [decidable_eq α] [∀a, encodable (π a)] : trunc (encodable (Πa, π a)) := (encodable.trunc_encodable_of_fintype α).bind $ λa, (@fintype_arrow α (Σa, π a) _ _ (@encodable.sigma _ _ a _)).bind $ λf, trunc.mk $ @encodable.of_equiv _ _ (@encodable.subtype _ _ f _) (equiv.pi_equiv_subtype_sigma α π) end encodable namespace denumerable variables {α : Type*} {β : Type*} [denumerable α] [denumerable β] open encodable section list theorem denumerable_list_aux : ∀ n : ℕ, ∃ a ∈ @decode_list α _ n, encode_list a = n | 0 := ⟨_, rfl, rfl⟩ | (succ v) := begin cases e : unpair v with v₁ v₂, have h := unpair_le_right v, rw e at h, rcases have v₂ < succ v, from lt_succ_of_le h, denumerable_list_aux v₂ with ⟨a, h₁, h₂⟩, simp at h₁, simp [decode_list, e, h₂, h₁, encode_list, mkpair_unpair' e] end instance denumerable_list : denumerable (list α) := ⟨denumerable_list_aux⟩ @[simp] theorem list_of_nat_zero : of_nat (list α) 0 = [] := rfl @[simp] theorem list_of_nat_succ (v : ℕ) : of_nat (list α) (succ v) = of_nat α v.unpair.1 :: of_nat (list α) v.unpair.2 := of_nat_of_decode $ show decode_list (succ v) = _, begin cases e : unpair v with v₁ v₂, simp [decode_list, e], rw [show decode_list v₂ = decode (list α) v₂, from rfl, decode_eq_of_nat]; refl end end list section multiset def lower : list ℕ → ℕ → list ℕ | [] n := [] | (m :: l) n := (m - n) :: lower l m def raise : list ℕ → ℕ → list ℕ | [] n := [] | (m :: l) n := (m + n) :: raise l (m + n) lemma lower_raise : ∀ l n, lower (raise l n) n = l | [] n := rfl | (m :: l) n := by simp [raise, lower, nat.add_sub_cancel, lower_raise] lemma raise_lower : ∀ {l n}, list.sorted (≤) (n :: l) → raise (lower l n) n = l | [] n h := rfl | (m :: l) n h := have n ≤ m, from list.rel_of_sorted_cons h _ (l.mem_cons_self _), by simp [raise, lower, nat.add_sub_cancel' this, raise_lower (list.sorted_of_sorted_cons h)] lemma raise_chain : ∀ l n, list.chain (≤) n (raise l n) | [] n := list.chain.nil | (m :: l) n := list.chain.cons (nat.le_add_left _ _) (raise_chain _ _) lemma raise_sorted : ∀ l n, list.sorted (≤) (raise l n) | [] n := list.sorted_nil | (m :: l) n := (list.chain_iff_pairwise (@le_trans _ _)).1 (raise_chain _ _) /- Warning: this is not the same encoding as used in `encodable` -/ instance multiset : denumerable (multiset α) := mk' ⟨ λ s : multiset α, encode $ lower ((s.map encode).sort (≤)) 0, λ n, multiset.map (of_nat α) (raise (of_nat (list ℕ) n) 0), λ s, by have := raise_lower (list.sorted_cons.2 ⟨λ n _, zero_le n, (s.map encode).sort_sorted _⟩); simp [-multiset.coe_map, this], λ n, by simp [-multiset.coe_map, list.merge_sort_eq_self _ (raise_sorted _ _), lower_raise]⟩ end multiset section finset def lower' : list ℕ → ℕ → list ℕ | [] n := [] | (m :: l) n := (m - n) :: lower' l (m + 1) def raise' : list ℕ → ℕ → list ℕ | [] n := [] | (m :: l) n := (m + n) :: raise' l (m + n + 1) lemma lower_raise' : ∀ l n, lower' (raise' l n) n = l | [] n := rfl | (m :: l) n := by simp [raise', lower', nat.add_sub_cancel, lower_raise'] lemma raise_lower' : ∀ {l n}, (∀ m ∈ l, n ≤ m) → list.sorted (<) l → raise' (lower' l n) n = l | [] n h₁ h₂ := rfl | (m :: l) n h₁ h₂ := have n ≤ m, from h₁ _ (l.mem_cons_self _), by simp [raise', lower', nat.add_sub_cancel' this, raise_lower' (list.rel_of_sorted_cons h₂ : ∀ a ∈ l, m < a) (list.sorted_of_sorted_cons h₂)] lemma raise'_chain : ∀ l {m n}, m < n → list.chain (<) m (raise' l n) | [] m n h := list.chain.nil | (a :: l) m n h := list.chain.cons (lt_of_lt_of_le h (nat.le_add_left _ _)) (raise'_chain _ (lt_succ_self _)) lemma raise'_sorted : ∀ l n, list.sorted (<) (raise' l n) | [] n := list.sorted_nil | (m :: l) n := (list.chain_iff_pairwise (@lt_trans _ _)).1 (raise'_chain _ (lt_succ_self _)) def raise'_finset (l : list ℕ) (n : ℕ) : finset ℕ := ⟨raise' l n, (raise'_sorted _ _).imp (@ne_of_lt _ _)⟩ /- Warning: this is not the same encoding as used in `encodable` -/ instance finset : denumerable (finset α) := mk' ⟨ λ s : finset α, encode $ lower' ((s.map (eqv α).to_embedding).sort (≤)) 0, λ n, finset.map (eqv α).symm.to_embedding (raise'_finset (of_nat (list ℕ) n) 0), λ s, finset.eq_of_veq $ by simp [-multiset.coe_map, raise'_finset, raise_lower' (λ n _, zero_le n) (finset.sort_sorted_lt _)], λ n, by simp [-multiset.coe_map, finset.map, raise'_finset, finset.sort, list.merge_sort_eq_self (≤) ((raise'_sorted _ _).imp (@le_of_lt _ _)), lower_raise']⟩ end finset end denumerable namespace equiv def list_nat_equiv_nat : list ℕ ≃ ℕ := denumerable.eqv _ def list_equiv_self_of_equiv_nat {α : Type} (e : α ≃ ℕ) : list α ≃ α := calc list α ≃ list ℕ : list_equiv_of_equiv e ... ≃ ℕ : list_nat_equiv_nat ... ≃ α : e.symm end equiv
75039ab417399ddeb4c2132749f547dbd009bfec
a45212b1526d532e6e83c44ddca6a05795113ddc
/src/category_theory/instances/Top/basic.lean
bff076e17bd898d5c4b52850632cdd58118c8386
[ "Apache-2.0" ]
permissive
fpvandoorn/mathlib
b21ab4068db079cbb8590b58fda9cc4bc1f35df4
b3433a51ea8bc07c4159c1073838fc0ee9b8f227
refs/heads/master
1,624,791,089,608
1,556,715,231,000
1,556,715,231,000
165,722,980
5
0
Apache-2.0
1,552,657,455,000
1,547,494,646,000
Lean
UTF-8
Lean
false
false
942
lean
-- Copyright (c) 2017 Scott Morrison. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Authors: Patrick Massot, Scott Morrison, Mario Carneiro import category_theory.concrete_category import topology.order open category_theory open topological_space universe u namespace category_theory.instances /-- The category of topological spaces and continuous maps. -/ @[reducible] def Top : Type (u+1) := bundled topological_space instance topological_space_unbundled (x : Top) : topological_space x := x.str namespace Top instance concrete_category_continuous : concrete_category @continuous := ⟨@continuous_id, @continuous.comp⟩ def discrete : Type u ⥤ Top.{u} := { obj := λ X, ⟨X, ⊤⟩, map := λ X Y f, ⟨f, continuous_top⟩ } def trivial : Type u ⥤ Top.{u} := { obj := λ X, ⟨X, ⊥⟩, map := λ X Y f, ⟨f, continuous_bot⟩ } end Top end category_theory.instances
4e3fc33a7d9686b5d61b4dde63b7baf1ac67c3b3
48eee836fdb5c613d9a20741c17db44c8e12e61c
/src/util/identities.lean
8f18d9230c722dae9d1a92a44c8fbb40fbcc8142
[ "Apache-2.0" ]
permissive
fgdorais/lean-universal
06430443a4abe51e303e602684c2977d1f5c0834
9259b0f7fb3aa83a9e0a7a3eaa44c262e42cc9b1
refs/heads/master
1,592,479,744,136
1,589,473,399,000
1,589,473,399,000
196,287,552
1
1
null
null
null
null
UTF-8
Lean
false
false
15,023
lean
-- Copyright © 2019 François G. Dorais. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. import .default import .meta.default meta structure identity_info := (to_name : name) (cl_name : option name) (el_name : option name) (univ_params : list name) (params : expr_ctx) (vars : list (level × name × expr)) (eqns : list (level × expr × expr × expr)) (is_trusted : bool) namespace identity_info variable (info : identity_info) include info meta def num_vars : nat := info.vars.length meta def num_hyps : nat := info.eqns.length - 1 meta def type : expr := info.params.pi (expr.sort level.zero) meta def eqn : expr := let bi : binder_info := if info.num_hyps = 0 then binder_info.default else binder_info.strict_implicit in let vars : expr_ctx := info.vars.enum.map $ λ ⟨k, _, n, t⟩, (n, t.lift_vars 0 (info.vars.length - k - 1), bi) in let eqns : list expr := info.eqns.map $ λ ⟨lvl, typ, lhs, rhs⟩, let typ := typ.lift_vars 0 vars.length in let lhs := vars.app_beta (lhs.lift_vars 0 vars.length) in let rhs := vars.app_beta (rhs.lift_vars 0 vars.length) in expr.mk_app (expr.const `eq [lvl]) [typ, lhs, rhs] in let eqn : expr := eqns.tail.foldl (λ q e, expr.pi `h binder_info.default e (q.lift_vars 0 1) ) eqns.head in vars.pi eqn end identity_info namespace identity open exceptional meta def get_info_aux_1 : expr_ctx → list (expr × expr × expr) × expr_ctx | vars@((n,t,b)::ctx) := match t with | `(@eq %%typ %%lhs %%rhs) := let (eqns, vars) := get_info_aux_1 ctx in let typ := typ.lower_vars 0 (eqns.length + vars.length) in let lhs := vars.lam (lhs.lower_vars 0 eqns.length) in let rhs := vars.lam (rhs.lower_vars 0 eqns.length) in ((typ, lhs, rhs) :: eqns, vars) | _ := ([], vars) end | [] := ([],[]) meta def get_info_aux : expr → list (name × expr) × list (expr × expr × expr) := λ e, let (e, ctx) := expr_ctx.get_ctx_pi e in let (eqns, ctx) := get_info_aux_1 (ctx.add `_ e) in let vars : list (name × expr) := ctx.enum.map (λ ⟨k,n,t,_⟩, (n, t.lower_vars 0 (ctx.length - k - 1))) in (vars, eqns) meta def get_info (decl : declaration) (clname : opt_param (option name) none) (elname : opt_param (option name) none) : exceptional identity_info := let (e, params) := expr_ctx.get_ctx_lam decl.value in let (vars, eqns) := get_info_aux e in vars.mmap (λ ⟨nm, typ⟩, match typ with | expr.var i := match list.nth params i with | some (_, expr.sort lvl, _) := success (lvl, nm, typ) | _ := fail "dom sort error" end | _ := fail $ "dom sort error" end) >>= λ vars, eqns.mmap (λ ⟨typ,lhs,rhs⟩, match typ with | expr.var i := match list.nth params i with | some (_, expr.sort lvl, _) := success (lvl, typ, lhs, rhs) | _ := fail "cod sort error" end | _ := fail "cod sort error" end) >>= λ eqns, success { to_name := decl.to_name , cl_name := clname , el_name := elname , univ_params := decl.univ_params , params := params , vars := vars , eqns := eqns , is_trusted := decl.is_trusted } meta def mk_decl (info : identity_info) : declaration := let itype : expr := info.params.pi (expr.sort level.zero) in let vars : expr_ctx := info.vars.enum.map (λ ⟨k, _, n, t⟩, (n, t.lift_vars 0 (info.vars.length - k - 1), binder_info.default)) in let eqns : list expr := info.eqns.map (λ ⟨lvl, typ, lhs, rhs⟩, let typ := typ.lift_vars 0 vars.length in let lhs := vars.app (lhs.lift_vars 0 vars.length) in let rhs := vars.app (rhs.lift_vars 0 vars.length) in expr.mk_app (expr.const `eq [lvl]) [typ, lhs, rhs] ) in let ivalue : expr := info.params.lam info.eqn in declaration.defn info.to_name info.univ_params itype ivalue reducibility_hints.abbrev tt meta def mk_class : identity_info → inductive_declaration × declaration := λ info, let clname : name := info.cl_name.get_or_else (info.to_name ++ `class) in let elname : name := info.el_name.get_or_else (info.to_name ++ `elim) in let ls : list level := info.univ_params.map level.param in let params : expr_ctx := info.params.map (λ ⟨n, e, _⟩, (n, e, binder_info.implicit)) in let cltype : expr := info.type in let ctx : expr_ctx := info.params.add `h info.eqn in let clcons : expr := expr.const clname ls in let clcons : expr := info.params.app clcons in let clcons : expr := ctx.pi (clcons.lift_vars 0 1) in let clind : inductive_declaration := { to_name := clname , univ_params := info.univ_params , type := cltype , num_params := info.params.length , num_indices := 0 , recursor := none , constructors := [(clname ++ `intro, clcons)] , is_trusted := info.is_trusted } in let clinst : expr := expr.const clname ls in let clinst : expr := info.params.app clinst in let ctx : expr_ctx := info.params.add `_inst clinst binder_info.inst_implicit in let eltype : expr := ctx.pi (info.eqn.lift_vars 0 1) in let elvalue : expr := expr.const (clname ++ `rec) (level.zero::ls) in let elvalue : expr := info.params.app elvalue in let elvalue : expr := expr.app elvalue info.eqn in let eid : expr := expr.app (expr.const `id [level.zero]) info.eqn in let elvalue : expr := expr.app elvalue eid in let elvalue : expr := info.params.lam elvalue in let eldecl := declaration.defn elname info.univ_params eltype elvalue reducibility_hints.abbrev info.is_trusted in (clind, eldecl) meta def mk_pattern_name (vars : nat) (hyps : nat := 0) : name := if hyps = 0 then mk_sub_name `algebra.identity vars else mk_sub_name (mk_sub_name `algebra.identity vars) hyps meta def mk_pattern_decl (vars : nat) (hyps : nat := 0) : inductive_declaration × declaration := let pname : name := mk_pattern_name vars hyps in let dls : list level := level.sub_params `u vars 1 in let dlm : level := level.list_max dls in let dom : expr_ctx := (mk_sub_names `α vars 1).zip (dls.map (λ l, (expr.sort l, binder_info.implicit))) in let cls : list level := level.sub_params `v (hyps+1) 1 in let cod : expr_ctx := (mk_sub_names `β (hyps+1) 1).zip (cls.map (λ l, (expr.sort l, binder_info.implicit))) in let var : expr_ctx := (mk_sub_names `x vars 1).reverse.map (λ n, (n, expr.var (vars + hyps), binder_info.default)) in let ctx : expr_ctx := cod.reverse ++ dom.reverse in let fts : list expr := (list.range (hyps+1)).reverse.map (λ i, expr.lift_vars (var.pi (expr.var (vars+hyps-i))) 0 i) in let lhs : expr_ctx := (mk_sub_names `lhs (hyps+1) 1).reverse.zip (fts.map (λ e, (e, binder_info.default))) in let rhs : expr_ctx := (mk_sub_names `rhs (hyps+1) 1).reverse.zip (fts.map (λ e, (e.lift_vars 0 (hyps+1), binder_info.default))) in let ctx : expr_ctx := rhs ++ lhs ++ cod.reverse ++ dom.reverse in let ptype := ctx.pi (expr.sort level.zero) in let var : expr_ctx := var.lift_vars 0 (2 * hyps + 2) in let ctx : expr_ctx := rhs ++ lhs ++ cod.reverse ++ dom.reverse in let eql : list expr := (list.range (hyps+1)).map (λ i, var.app (expr.var (vars + 2 * hyps + 1 - i))) in let eqr : list expr := (list.range (hyps+1)).map (λ i, var.app (expr.var (vars + hyps - i))) in let eqs : list expr := (cls.zip $ list.zip eql eqr).enum.map (λ e : nat × level × expr × expr, expr.mk_app (expr.const `eq [e.snd.fst]) [expr.var (vars+3*hyps+2-e.fst), e.snd.snd.fst, e.snd.snd.snd]) in let eqn : expr := var.pi (eqs.reverse.tail.foldl (λ e h, expr.pi `h binder_info.default h (e.lift_vars 0 1)) eqs.reverse.head) in let cctx := ctx.add `_ eqn in let pcons := cctx.pi ((ctx.app (expr.const pname (dls++cls))).lift_vars 0 1) in let pdecl : inductive_declaration := { to_name := pname , univ_params := mk_sub_names `u vars 1 ++ mk_sub_names `v (hyps+1) 1 , type := ptype , num_params := vars + 3 * hyps + 3 , num_indices := 0 , recursor := some (pname ++ `rec) , constructors := [(pname ++ `intro, pcons)] , is_trusted := tt } in let ectx := ctx.add `_inst (ctx.app (expr.const pname (dls++cls))) binder_info.inst_implicit in let etype := ectx.pi (eqn.lift_vars 0 1) in let evalue : expr := ctx.app (expr.const (pname ++ `rec) (level.zero :: dls ++ cls)) in let evalue : expr := expr.app evalue eqn in let evalue : expr := expr.app evalue (expr.app (expr.const `id [level.zero]) eqn) in let evalue : expr := ctx.lam evalue in let edecl := declaration.defn (pname ++ `elim) pdecl.univ_params etype evalue reducibility_hints.abbrev tt in (pdecl, edecl) meta def mk_pattern_inst (info : identity_info) : declaration × declaration := let pcname : name := mk_pattern_name info.num_vars info.num_hyps in let pename : name := pcname ++ `elim in let piname : name := pcname ++ `intro in let plvls : list level := info.vars.reverse.map prod.fst ++ info.eqns.reverse.map prod.fst in let pargs : list expr := info.vars.reverse.map (λ ⟨_,_,t⟩, t) ++ info.eqns.reverse.map (λ ⟨_,t,_,_⟩, t) ++ info.eqns.reverse.map (λ ⟨_,_,l,_⟩, l) ++ info.eqns.reverse.map (λ ⟨_,_,_,r⟩, r) in let pclass : expr := expr.mk_app (expr.const pcname plvls) pargs in let pintro : expr := expr.mk_app (expr.const piname plvls) pargs in let pelim : expr := expr.mk_app (expr.const pename plvls) pargs in let icname : name := info.cl_name.get_or_else (info.to_name ++ `class) in let iiname : name := icname ++ `intro in let iename : name := info.el_name.get_or_else (info.to_name ++ `elim) in let ilvls : list level := info.univ_params.map level.param in let iclass : expr := info.params.app (expr.const icname ilvls) in let iintro : expr := info.params.app (expr.const iiname ilvls) in let ielim : expr := info.params.app (expr.const iename ilvls) in let toctx : expr_ctx := info.params.add `_inst iclass binder_info.inst_implicit in let totype : expr := toctx.pi (pclass.lift_vars 0 1) in let toarg : expr := expr.app (ielim.lift_vars 0 1) (expr.var 0) in let tovalue : expr := expr.app (pintro.lift_vars 0 1) toarg in let tovalue : expr := toctx.lam tovalue in let todecl := declaration.defn (icname ++ `to_pattern) info.univ_params totype tovalue reducibility_hints.abbrev info.is_trusted in let ofctx : expr_ctx := info.params.add `_inst pclass binder_info.inst_implicit in let oftype : expr := ofctx.pi (iclass.lift_vars 0 1) in let ofarg : expr := expr.app (pelim.lift_vars 0 1) (expr.var 0) in let ofvalue : expr := expr.app (iintro.lift_vars 0 1) ofarg in let ofvalue : expr := ofctx.lam ofvalue in let ofdecl := declaration.defn (icname ++ `of_pattern) info.univ_params oftype ofvalue reducibility_hints.abbrev info.is_trusted in (todecl, ofdecl) meta def mk_identity_instance (th : declaration) : exceptional declaration := let (e, ctx) := expr_ctx.get_ctx_pi th.type in match e.get_app_fn with | (expr.const nm lvls) := if nm.get_prefix = `algebra.identity then success (nm.get_suffix, lvls, e.get_app_args) else fail "invalid identity theorem" | _ := fail "invalid identity theorem" end >>= λ ⟨iname, ilvls, iargs⟩, let targ : expr := expr.const th.to_name (th.univ_params.map level.param) in let targ : expr := ctx.app targ in let itype : expr := expr.const (`algebra.class ++ iname) ilvls in let itype : expr := ctx.pi (expr.mk_app itype iargs) in let ivalue : expr := expr.const (`algebra.class ++ iname ++ `intro) ilvls in let ivalue : expr := expr.mk_app ivalue iargs in let ivalue : expr := ctx.lam (expr.app ivalue targ) in success $ declaration.defn (th.to_name ++ `_identity) th.univ_params itype ivalue reducibility_hints.abbrev tt end identity meta def theory.mk_infer : structure_declaration → exceptional declaration := λ sd, let (_, ctx) := expr_ctx.get_ctx_pi sd.type in sd.fields.reverse.enum.mmap (λ ⟨k, fn, ft⟩, let (ft, _) := expr_ctx.get_ctx_pi ft in let ft := ft.lower_vars 0 1 in match ft.get_app_fn with | expr.const nm ls := if nm.get_prefix = `algebra.identity then let cl : expr := expr.const (nm.update_prefix `algebra.class) ls in let cl : expr := expr.mk_app cl ft.get_app_args in let cl : expr := expr.lift_vars cl 0 (sd.num_fields - k - 1) in let el : expr := expr.const (nm.update_prefix `algebra) ls in let el : expr := expr.mk_app el ft.get_app_args in let el : expr := expr.app (el.lift_vars 0 sd.num_fields) (expr.var k) in exceptional.success (fn.get_suffix, cl, el) else exceptional.fail "invalid axiom" | e := exceptional.fail "invalid axiom" end) >>= λ axs, let axarg : list expr := axs.map (λ ⟨_,_,el⟩, el) in let axctx : expr_ctx := axs.map (λ ⟨n,cl,_⟩, (n, cl, binder_info.inst_implicit)) in let iftype : expr := expr.const sd.to_name (sd.univ_params.map level.param) in let iftype : expr := ctx.pi (axctx.pi ((ctx.app iftype).lift_vars 0 axctx.length)) in let ifvalue : expr := expr.const sd.mk_name (sd.univ_params.map level.param) in let ifvalue : expr := ctx.app ifvalue in let ifvalue : expr := expr.mk_app (ifvalue.lift_vars 0 axctx.length) axarg.reverse in let ifvalue : expr := ctx.lam (axctx.lam ifvalue) in exceptional.success $ declaration.defn (sd.to_name ++ `infer) sd.univ_params iftype ifvalue reducibility_hints.abbrev sd.is_trusted meta def tactic.add_pattern_decl (vars : nat) (hyps : nat := 0) : tactic unit := let (idecl, edecl) := identity.mk_pattern_decl vars hyps in tactic.add_ind idecl >> tactic.add_decl edecl >> tactic.set_basic_attribute `class idecl.to_name tt section attributes open tactic @[user_attribute] meta def algebra.identity_decl_attr : user_attribute := { name := `identity , descr := "declare an algebraic quasi-identity" , after_set := some $ λ nm _ _, do { guard (nm.get_prefix = `algebra.identity), decl ← get_decl nm, info ← identity.get_info decl (some $ nm.update_prefix `algebra.class) (some $ nm.update_prefix `algebra), (cldecl, eldecl) ← pure $ identity.mk_class info, add_ind cldecl >> set_basic_attribute `class cldecl.to_name tt, add_decl eldecl >> set_basic_attribute `reducible eldecl.to_name tt, (resolve_constant (identity.mk_pattern_name info.num_vars info.num_hyps) >> tactic.skip) <|> tactic.add_pattern_decl info.num_vars info.num_hyps, (todecl, ofdecl) ← pure $ identity.mk_pattern_inst info, add_decl todecl >> tactic.set_basic_attribute `instance todecl.to_name tt, add_decl ofdecl, skip } } @[user_attribute] meta def algebra.identity_inst_attr : user_attribute unit (option name) := { name := `identity_instance , descr := "declare an algebraic quasi-identity instance" , parser := optional lean.parser.ident , after_set := some $ λ nm prio perm, do { decl ← get_decl nm, arg ← algebra.identity_inst_attr.get_param nm, match arg with | some _ := fail "not implemented" | none := do { d ← identity.mk_identity_instance decl, add_decl d, set_basic_attribute `instance d.to_name perm (some prio) } end } } @[user_attribute] meta def algebra.theory_attr : user_attribute := { name := `theory , descr := "declare an algebraic theory" , after_set := some $ λ nm prio perm, do { decl ← get_str nm, infer ← theory.mk_infer decl, add_decl infer, decl.fields.mfoldr (λ ⟨fn,_⟩ t, algebra.identity_inst_attr.set fn none perm (some prio)) () } } end attributes
62b3a828b2cb111459f036baa82756828384f056
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/test/finish1.lean
533784abf932ef0a728ec6ee13b73cf9bad7b919
[ "Apache-2.0" ]
permissive
jjgarzella/mathlib
96a345378c4e0bf26cf604aed84f90329e4896a2
395d8716c3ad03747059d482090e2bb97db612c8
refs/heads/master
1,686,480,124,379
1,625,163,323,000
1,625,163,323,000
281,190,421
2
0
Apache-2.0
1,595,268,170,000
1,595,268,169,000
null
UTF-8
Lean
false
false
4,824
lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad Examples to test finish. (The designations "clarify," "safe," "iauto," etc. are from a previous tableau prover.) -/ import tactic.finish open auto section variables A B C D : Prop /- clarify -/ example (H : ¬ A) (H' : A) : C := by finish example (H₁ : A ∧ A ∧ B) (H₂ : A ∧ C ∧ B) : A := by finish /- safe -/ example (H : A) (H₁ : ¬ B) : ¬ (A → B) := by finish example : A ∨ B → B ∨ A := by finish example : A ∧ B → B ∧ A := by finish example (H : A) (H₁ : A → B) (H₂ : B → C) : C := by finish example (H₁ : A ∧ B) (H₂ : C ∧ B) : C := by finish example (HA : A) (HB : B) (HC : C) (HD : D) : (A ∧ B) ∧ (C ∧ D) := by finish example (H₁ : A ∧ B) (H₂ : B ∧ ¬ C) : A ∨ C := by finish example : (A → B) ∧ (B → C) → A → C := by finish example : (A → B) ∨ (B → A) := by finish example : ((A → B) → A) → A := by finish /- iauto -/ example (H : A) (H₁ : ¬ B) : ¬ (A → B) := by finish example : ¬ (A ↔ ¬ A) := by finish example (H : A ↔ B) (H₁ : A ∧ B → C) (H₂ : ¬ A ∧ ¬ B → C) : C := by finish example (H : A ↔ B) (H₁ : (A ∧ ¬ B) ∨ (¬ A ∧ B)) : C := by finish example (H : A → B) (H₁ : A) : B := by finish example (H : A → B) (H₁ : B → C) : A → C := by finish example (H : A → B ∨ C) (H₁ : B → D) (H₂ : C → D) : A → D := by finish example : A ∨ B → B ∨ A := by finish /- using injectivity -/ section open nat example (x y : ℕ) : succ x = succ y → x = y ∨ x = succ y := by finish example (x y z : ℕ) : succ (succ x) = succ y ∧ y = succ z → y = succ x ∧ succ x = succ z := by finish end /- -- Examples with quantifiers -/ section variables (X : Type) (P Q R : X → Prop) (T : X → X → Prop) (a b : X) /- auto -/ example (H : ∀ x, P x → Q x) (H₁ : ∀ x, P x) : Q a := by finish example (H : ∀ x, P x → Q x) (H₁ : P a) : Q a := by finish /- iauto -/ example (H₁ : P a) (H₂ : P b) : ∃ x, P x := by finish example (H₁ : P a) (H₂ : P b) (H₃ : Q b) : ∃ x, P x ∧ Q x := by finish example (H₁ : P b) (H₂ : Q b) (H₃ : P a) : ∃ x, P x ∧ Q x := by finish example (H : ∀ x, P x → Q x ∧ R x) (a : X) (H₁ : P a) : R a ∧ Q a := by finish example (H : ∃ x, P x ∧ Q x) : ∃ x, Q x ∧ P x := by finish -- not valid in dependent type theory! -- example : ∃ x, ((∃ y, P y) → P x) := -- by auto' /- Beyond the scope of finish. example (H : ∃ x : X, x = x) : ∃ x, ((∃ y, P y) → P x) := by finish example : (∃ x, ∀ y, T x y) → ∀ y, ∃ x, T x y := by finish -/ end example (x y z : ℕ) (p : ℕ → Prop) (h₀ : x = y) (h₁ : y = z) (h₂ : ∀ w, w = z → p w) : p x := by finish end /- more examples -/ constant foo : Prop axiom not_foo : ¬ foo section variables a b c d : Prop example : a ∧ b → a := by finish example : a → (a → b) → (b → c) ∧ (d → ¬ c) → ¬ d := by finish example : a ∨ b → b ∨ a := by finish example : ¬ (a ↔ ¬ a) := begin finish end /- examples of tactics that leave goals -/ /- example : a ∨ b ∨ foo → b ∨ a := begin clarify, admit end example : a ∨ b ∨ foo ∨ foo → b ∨ a := begin safe, admit end example : a ∨ b ∨ c → ¬ a → ¬ b → d := begin safe, admit end -/ end section variables (a b c : ℕ) (p q : ℕ → Prop) (r : ℕ → ℕ → Prop) variables (P Q R : Prop) variable (g : bool → nat) example (h₁ : ∀ x, p x → q x) (h₂ : ∀ x, p x) : q a := by finish example (h₁ : p a) : ∃ x, p x := by finish example (h₁ : p a) (h₂ : p b) (h₃ : q b) : ∃ x, p x ∧ q x := by finish example (h : ∃ x, p x ∧ r x x) (h' : ∀ x, r x x → q x) : ∃ x, p x ∧ q x := by finish example (h : ∃ x, q x ∧ p x) : ∃ x, p x ∧ q x := by finish example (h₁ : ∀ x, q x → p x) (h₃ : q a) : ∃ x, p x := by finish example (h₁ : ∀ x, p x → q x → false) (h₂ : p a) (h₃ : p b) (h₄ : q b) : false := by finish example (h : ∀ x, p x) (h₁ : ∀ x, p x → q x) : ∀ x, q x := by finish example (h : ∃ x, p x) (h₁ : ∀ x, p x → q x) : ∃ x, q x := by finish example (h : ¬ ∀ x, ¬ p x) (h₁ : ∀ x, p x → q x) (h₂ : ∀ x, ¬ q x) : false := by finish /- example (h : p a) (h' : p a → false) : false := by finish -/ end section variables a b c d : Prop variables (p q : ℕ → Prop) (r : ℕ → ℕ → Prop) example (h : ¬ ∀ x, (∃ y, r x y) → p x) : true := begin normalize_hyps {}, trivial end example (h₁ : a → b ∨ c) (h₂ : ¬ b) : a → c := begin simp * at *, assumption end end
13a38c7bd9971bdbf77bee8d80dc9b9afce38801
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/topology/homotopy/equiv.lean
641495cefeb9870a4e0e3293ce0eb4be280e6f83
[ "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
5,181
lean
/- Copyright (c) 2021 Shing Tak Lam. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Shing Tak Lam -/ import topology.homotopy.basic /-! # Homotopy equivalences between topological spaces In this file, we define homotopy equivalences between topological spaces `X` and `Y` as a pair of functions `f : C(X, Y)` and `g : C(Y, X)` such that `f.comp g` and `g.comp f` are both homotopic to `id`. ## Main definitions - `continuous_map.homotopy_equiv` is the type of homotopy equivalences between topological spaces. ## Notation We introduce the notation `X ≃ₕ Y` for `continuous_map.homotopy_equiv X Y` in the `continuous_map` locale. -/ universes u v w variables {X : Type u} {Y : Type v} {Z : Type w} variables [topological_space X] [topological_space Y] [topological_space Z] namespace continuous_map /-- A homotopy equivalence between topological spaces `X` and `Y` are a pair of functions `to_fun : C(X, Y)` and `inv_fun : C(Y, X)` such that `to_fun.comp inv_fun` and `inv_fun.comp to_fun` are both homotopic to `id`. -/ @[ext] structure homotopy_equiv (X : Type u) (Y : Type v) [topological_space X] [topological_space Y] := (to_fun : C(X, Y)) (inv_fun : C(Y, X)) (left_inv : (inv_fun.comp to_fun).homotopic (continuous_map.id X)) (right_inv : (to_fun.comp inv_fun).homotopic (continuous_map.id Y)) localized "infix (name := continuous_map.homotopy_equiv) ` ≃ₕ `:25 := continuous_map.homotopy_equiv" in continuous_map namespace homotopy_equiv instance : has_coe_to_fun (homotopy_equiv X Y) (λ _, X → Y) := ⟨λ h, h.to_fun⟩ @[simp] lemma to_fun_eq_coe (h : homotopy_equiv X Y) : (h.to_fun : X → Y) = h := rfl @[continuity] lemma continuous (h : homotopy_equiv X Y) : continuous h := h.to_fun.continuous end homotopy_equiv end continuous_map open_locale continuous_map namespace homeomorph /-- Any homeomorphism is a homotopy equivalence. -/ def to_homotopy_equiv (h : X ≃ₜ Y) : X ≃ₕ Y := { to_fun := ⟨h⟩, inv_fun := ⟨h.symm⟩, left_inv := by { convert continuous_map.homotopic.refl _, ext, simp }, right_inv := by { convert continuous_map.homotopic.refl _, ext, simp } } @[simp] lemma coe_to_homotopy_equiv (h : X ≃ₜ Y) : ⇑(h.to_homotopy_equiv) = h := rfl end homeomorph namespace continuous_map namespace homotopy_equiv /-- If `X` is homotopy equivalent to `Y`, then `Y` is homotopy equivalent to `X`. -/ def symm (h : X ≃ₕ Y) : Y ≃ₕ X := { to_fun := h.inv_fun, inv_fun := h.to_fun, left_inv := h.right_inv, right_inv := h.left_inv } @[simp] lemma coe_inv_fun (h : homotopy_equiv X Y) : (⇑h.inv_fun : Y → X) = ⇑h.symm := rfl /-- 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 : X ≃ₕ Y) : X → Y := h /-- See Note [custom simps projection]. We need to specify this projection explicitly in this case, because it is a composition of multiple projections. -/ def simps.symm_apply (h : X ≃ₕ Y) : Y → X := h.symm initialize_simps_projections homotopy_equiv (to_fun_to_fun -> apply, inv_fun_to_fun -> symm_apply, -to_fun, -inv_fun) /-- Any topological space is homotopy equivalent to itself. -/ @[simps] def refl (X : Type u) [topological_space X] : X ≃ₕ X := (homeomorph.refl X).to_homotopy_equiv instance : inhabited (homotopy_equiv unit unit) := ⟨refl unit⟩ /-- If `X` is homotopy equivalent to `Y`, and `Y` is homotopy equivalent to `Z`, then `X` is homotopy equivalent to `Z`. -/ @[simps] def trans (h₁ : X ≃ₕ Y) (h₂ : Y ≃ₕ Z) : X ≃ₕ Z := { to_fun := h₂.to_fun.comp h₁.to_fun, inv_fun := h₁.inv_fun.comp h₂.inv_fun, left_inv := begin refine homotopic.trans _ h₁.left_inv, change ((h₁.inv_fun.comp h₂.inv_fun).comp (h₂.to_fun.comp h₁.to_fun)) with h₁.inv_fun.comp ((h₂.inv_fun.comp h₂.to_fun).comp h₁.to_fun), refine homotopic.hcomp _ (homotopic.refl _), refine homotopic.trans ((homotopic.refl _).hcomp h₂.left_inv) _, -- simp, rw continuous_map.id_comp, end, right_inv := begin refine homotopic.trans _ h₂.right_inv, change ((h₂.to_fun.comp h₁.to_fun).comp (h₁.inv_fun.comp h₂.inv_fun)) with h₂.to_fun.comp ((h₁.to_fun.comp h₁.inv_fun).comp h₂.inv_fun), refine homotopic.hcomp _ (homotopic.refl _), refine homotopic.trans ((homotopic.refl _).hcomp h₁.right_inv) _, rw id_comp, end } lemma symm_trans (h₁ : X ≃ₕ Y) (h₂ : Y ≃ₕ Z) : (h₁.trans h₂).symm = h₂.symm.trans h₁.symm := by ext; refl end homotopy_equiv end continuous_map open continuous_map namespace homeomorph @[simp] lemma refl_to_homotopy_equiv (X : Type u) [topological_space X] : (homeomorph.refl X).to_homotopy_equiv = homotopy_equiv.refl X := rfl @[simp] lemma symm_to_homotopy_equiv (h : X ≃ₜ Y) : h.symm.to_homotopy_equiv = h.to_homotopy_equiv.symm := rfl @[simp] lemma trans_to_homotopy_equiv (h₀ : X ≃ₜ Y) (h₁ : Y ≃ₜ Z) : (h₀.trans h₁).to_homotopy_equiv = h₀.to_homotopy_equiv.trans h₁.to_homotopy_equiv := rfl end homeomorph
3bb56a95f1b523d39b936dc8fc12aba78ef2f637
4950bf76e5ae40ba9f8491647d0b6f228ddce173
/src/algebra/quadratic_discriminant.lean
8f0a259ae8ccf65a5e3a7f4e415aa6f62358169d
[ "Apache-2.0" ]
permissive
ntzwq/mathlib
ca50b21079b0a7c6781c34b62199a396dd00cee2
36eec1a98f22df82eaccd354a758ef8576af2a7f
refs/heads/master
1,675,193,391,478
1,607,822,996,000
1,607,822,996,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
6,201
lean
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou -/ import algebra.invertible import tactic.linarith /-! # Quadratic discriminants and roots of a quadratic This file defines the discriminant of a quadratic and gives the solution to a quadratic equation. ## Main definition - `discrim a b c`: the discriminant of a quadratic `a * x * x + b * x + c` is `b * b - 4 * a * c`. ## Main statements - `quadratic_eq_zero_iff`: roots of a quadratic can be written as `(-b + s) / (2 * a)` or `(-b - s) / (2 * a)`, where `s` is a square root of the discriminant. - `quadratic_ne_zero_of_discrim_ne_square`: if the discriminant has no square root, then the corresponding quadratic has no root. - `discrim_le_zero`: if a quadratic is always non-negative, then its discriminant is non-positive. ## Tags polynomial, quadratic, discriminant, root -/ section ring variables {R : Type*} /-- Discriminant of a quadratic -/ def discrim [ring R] (a b c : R) : R := b^2 - 4 * a * c variables [integral_domain R] {a b c : R} /-- A quadratic has roots if and only if its discriminant equals some square. -/ lemma quadratic_eq_zero_iff_discrim_eq_square (h2 : (2 : R) ≠ 0) (ha : a ≠ 0) (x : R) : a * x * x + b * x + c = 0 ↔ discrim a b c = (2 * a * x + b) ^ 2 := begin split, { assume h, calc discrim a b c = 4 * a * (a * x * x + b * x + c) + b * b - 4 * a * c : by { rw [h, discrim], ring } ... = (2*a*x + b)^2 : by ring }, { assume h, have ha : 2 * 2 * a ≠ 0 := mul_ne_zero (mul_ne_zero h2 h2) ha, apply mul_left_cancel' ha, calc 2 * 2 * a * (a * x * x + b * x + c) = (2 * a * x + b) ^ 2 - (b ^ 2 - 4 * a * c) : by ring ... = 0 : by { rw [← h, discrim], ring } ... = 2*2*a*0 : by ring } end /-- A quadratic has no root if its discriminant has no square root. -/ lemma quadratic_ne_zero_of_discrim_ne_square (h2 : (2 : R) ≠ 0) (ha : a ≠ 0) (h : ∀ s : R, discrim a b c ≠ s * s) (x : R) : a * x * x + b * x + c ≠ 0 := begin assume h', rw [quadratic_eq_zero_iff_discrim_eq_square h2 ha, pow_two] at h', exact h _ h' end end ring section field variables {K : Type*} [field K] [invertible (2 : K)] {a b c x : K} /-- Roots of a quadratic -/ lemma quadratic_eq_zero_iff (ha : a ≠ 0) {s : K} (h : discrim a b c = s * s) (x : K) : a * x * x + b * x + c = 0 ↔ x = (-b + s) / (2 * a) ∨ x = (-b - s) / (2 * a) := begin have h2 : (2 : K) ≠ 0 := nonzero_of_invertible 2, rw [quadratic_eq_zero_iff_discrim_eq_square h2 ha, h, pow_two, mul_self_eq_mul_self_iff], have ne : 2 * a ≠ 0 := mul_ne_zero h2 ha, have : x = 2 * a * x / (2 * a) := (mul_div_cancel_left x ne).symm, have h₁ : 2 * a * ((-b + s) / (2 * a)) = -b + s := mul_div_cancel' _ ne, have h₂ : 2 * a * ((-b - s) / (2 * a)) = -b - s := mul_div_cancel' _ ne, split, { intro h', rcases h', { left, rw h', simpa [add_comm] }, { right, rw h', simpa [add_comm, sub_eq_add_neg] } }, { intro h', rcases h', { left, rw [h', h₁], ring }, { right, rw [h', h₂], ring } } end /-- A quadratic has roots if its discriminant has square roots -/ lemma exists_quadratic_eq_zero (ha : a ≠ 0) (h : ∃ s, discrim a b c = s * s) : ∃ x, a * x * x + b * x + c = 0 := begin rcases h with ⟨s, hs⟩, use (-b + s) / (2 * a), rw quadratic_eq_zero_iff ha hs, simp end /-- Root of a quadratic when its discriminant equals zero -/ lemma quadratic_eq_zero_iff_of_discrim_eq_zero (ha : a ≠ 0) (h : discrim a b c = 0) (x : K) : a * x * x + b * x + c = 0 ↔ x = -b / (2 * a) := begin have : discrim a b c = 0 * 0, by rw [h, mul_zero], rw [quadratic_eq_zero_iff ha this, add_zero, sub_zero, or_self] end end field section linear_ordered_field variables {K : Type*} [linear_ordered_field K] {a b c : K} /-- If a polynomial of degree 2 is always nonnegative, then its discriminant is nonpositive -/ lemma discrim_le_zero (h : ∀ x : K, 0 ≤ a * x * x + b * x + c) : discrim a b c ≤ 0 := begin rw [discrim, pow_two], obtain ha|rfl|ha : a < 0 ∨ a = 0 ∨ 0 < a := lt_trichotomy a 0, -- if a < 0 { by_cases hb : b = 0, { rw hb at *, rcases exists_lt_mul_self (-c / a) with ⟨x, hx⟩, have := mul_lt_mul_of_neg_left hx ha, rw [mul_div_cancel' _ (ne_of_lt ha), ← mul_assoc] at this, have h₂ := h x, linarith }, { by_cases hc' : c = 0, { rw hc' at *, have : -(a * -b * -b + b * -b + 0) = (1 - a) * (b * b), {ring}, have h := h (-b), rw [← neg_nonpos, this] at h, have : b * b ≤ 0 := nonpos_of_mul_nonpos_left h (by linarith), linarith }, { have h := h (-c / b), have : a * (-c / b) * (-c / b) + b * (-c / b) + c = a * ((c / b) * (c / b)), { rw mul_div_cancel' _ hb, ring }, rw this at h, have : 0 ≤ a := nonneg_of_mul_nonneg_right h (mul_self_pos $ div_ne_zero hc' hb), linarith [ha] } } }, -- if a = 0 { by_cases hb : b = 0, { rw [hb], linarith }, { have := h ((-c - 1) / b), rw [mul_div_cancel' _ hb] at this, linarith } }, -- if a > 0 { have := calc 4 * a * (a * (-(b / a) * (1 / 2)) * (-(b / a) * (1 / 2)) + b * (-(b / a) * (1 / 2)) + c) = (a * (b / a)) * (a * (b / a)) - 2 * (a * (b / a)) * b + 4 * a * c : by ring ... = -(b * b - 4 * a * c) : by { simp only [mul_div_cancel' b (ne_of_gt ha)], ring }, have ha' : 0 ≤ 4 * a, by linarith, have h := (mul_nonneg ha' (h (-(b / a) * (1 / 2)))), rw this at h, rwa ← neg_nonneg } end /-- If a polynomial of degree 2 is always positive, then its discriminant is negative, at least when the coefficient of the quadratic term is nonzero. -/ lemma discrim_lt_zero (ha : a ≠ 0) (h : ∀ x : K, 0 < a * x * x + b * x + c) : discrim a b c < 0 := begin have : ∀ x : K, 0 ≤ a*x*x + b*x + c := assume x, le_of_lt (h x), refine lt_of_le_of_ne (discrim_le_zero this) _, assume h', have := h (-b / (2 * a)), have : a * (-b / (2 * a)) * (-b / (2 * a)) + b * (-b / (2 * a)) + c = 0, { rw [quadratic_eq_zero_iff_of_discrim_eq_zero ha h' (-b / (2 * a))] }, linarith end end linear_ordered_field
4a0ebc797c326c9947505eb7e6d704e5806993d3
367134ba5a65885e863bdc4507601606690974c1
/src/field_theory/tower.lean
bb2c149d3337de702eb13f5aae200041abbb723e
[ "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
5,242
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 ring_theory.algebra_tower import linear_algebra.matrix /-! # Tower of field extensions In this file we prove the tower law for arbitrary extensions and finite extensions. Suppose `L` is a field extension of `K` and `K` is a field extension of `F`. Then `[L:F] = [L:K] [K:F]` where `[E₁:E₂]` means the `E₂`-dimension of `E₁`. In fact we generalize it to vector spaces, where `L` is not necessarily a field, but just a vector space over `K`. ## Implementation notes We prove two versions, since there are two notions of dimensions: `vector_space.dim` which gives the dimension of an arbitrary vector space as a cardinal, and `finite_dimensional.findim` which gives the dimension of a finitely-dimensional vector space as a natural number. ## Tags tower law -/ universes u v w u₁ v₁ w₁ open_locale classical big_operators section field open cardinal variables (F : Type u) (K : Type v) (A : Type w) variables [field F] [field K] [add_comm_group A] variables [algebra F K] [vector_space K A] [vector_space F A] [is_scalar_tower F K A] /-- Tower law: if `A` is a `K`-vector space and `K` is a field extension of `F` then `dim_F(A) = dim_F(K) * dim_K(A)`. -/ theorem dim_mul_dim' : (cardinal.lift.{v w} (vector_space.dim F K) * cardinal.lift.{w v} (vector_space.dim K A) : cardinal.{max w v}) = cardinal.lift.{w v} (vector_space.dim F A) := let ⟨b, hb⟩ := exists_is_basis F K, ⟨c, hc⟩ := exists_is_basis K A in by rw [← (vector_space.dim F K).lift_id, ← hb.mk_eq_dim, ← (vector_space.dim K A).lift_id, ← hc.mk_eq_dim, ← lift_umax.{w v}, ← (hb.smul hc).mk_eq_dim, mk_prod, lift_mul, lift_lift, lift_lift, lift_lift, lift_lift, lift_umax] /-- Tower law: if `A` is a `K`-vector space and `K` is a field extension of `F` then `dim_F(A) = dim_F(K) * dim_K(A)`. -/ theorem dim_mul_dim (F : Type u) (K A : Type v) [field F] [field K] [add_comm_group A] [algebra F K] [vector_space K A] [vector_space F A] [is_scalar_tower F K A] : vector_space.dim F K * vector_space.dim K A = vector_space.dim F A := by convert dim_mul_dim' F K A; rw lift_id namespace finite_dimensional theorem trans [finite_dimensional F K] [finite_dimensional K A] : finite_dimensional F A := let ⟨b, hb⟩ := exists_is_basis_finset F K in let ⟨c, hc⟩ := exists_is_basis_finset K A in of_fintype_basis $ hb.smul hc lemma right [hf : finite_dimensional F A] : finite_dimensional K A := let ⟨b, hb⟩ := iff_fg.1 hf in iff_fg.2 ⟨b, submodule.restrict_scalars_injective F _ _ $ by { rw [submodule.restrict_scalars_top, eq_top_iff, ← hb, submodule.span_le], exact submodule.subset_span }⟩ /-- Tower law: if `A` is a `K`-algebra and `K` is a field extension of `F` then `dim_F(A) = dim_F(K) * dim_K(A)`. -/ theorem findim_mul_findim [finite_dimensional F K] : findim F K * findim K A = findim F A := begin by_cases hA : finite_dimensional K A, { resetI, rcases exists_is_basis_finset F K with ⟨b, hb⟩, rcases exists_is_basis_finset K A with ⟨c, hc⟩, rw [findim_eq_card_basis hb, findim_eq_card_basis hc, findim_eq_card_basis (hb.smul hc), fintype.card_prod] }, { rw [findim_of_infinite_dimensional hA, mul_zero, findim_of_infinite_dimensional], exact mt (@right F K A _ _ _ _ _ _ _) hA } end instance linear_map (F : Type u) (V : Type v) (W : Type w) [field F] [add_comm_group V] [vector_space F V] [add_comm_group W] [vector_space F W] [finite_dimensional F V] [finite_dimensional F W] : finite_dimensional F (V →ₗ[F] W) := let ⟨b, hb⟩ := exists_is_basis_finset F V in let ⟨c, hc⟩ := exists_is_basis_finset F W in (matrix.to_lin hb hc).finite_dimensional lemma findim_linear_map (F : Type u) (V : Type v) (W : Type w) [field F] [add_comm_group V] [vector_space F V] [add_comm_group W] [vector_space F W] [finite_dimensional F V] [finite_dimensional F W] : findim F (V →ₗ[F] W) = findim F V * findim F W := let ⟨b, hb⟩ := exists_is_basis_finset F V in let ⟨c, hc⟩ := exists_is_basis_finset F W in by rw [linear_equiv.findim_eq (linear_map.to_matrix hb hc), matrix.findim_matrix, findim_eq_card_basis hb, findim_eq_card_basis hc, mul_comm] -- TODO: generalize by removing [finite_dimensional F K] -- V = ⊕F, -- (V →ₗ[F] K) = ((⊕F) →ₗ[F] K) = (⊕ (F →ₗ[F] K)) = ⊕K instance linear_map' (F : Type u) (K : Type v) (V : Type w) [field F] [field K] [algebra F K] [finite_dimensional F K] [add_comm_group V] [vector_space F V] [finite_dimensional F V] : finite_dimensional K (V →ₗ[F] K) := right F _ _ lemma findim_linear_map' (F : Type u) (K : Type v) (V : Type w) [field F] [field K] [algebra F K] [finite_dimensional F K] [add_comm_group V] [vector_space F V] [finite_dimensional F V] : findim K (V →ₗ[F] K) = findim F V := (nat.mul_right_inj $ show 0 < findim F K, from findim_pos).1 $ calc findim F K * findim K (V →ₗ[F] K) = findim F (V →ₗ[F] K) : findim_mul_findim _ _ _ ... = findim F V * findim F K : findim_linear_map F V K ... = findim F K * findim F V : mul_comm _ _ end finite_dimensional end field
49fd0f3675fc4d3a1cee4dbfa788e27b02ed5886
4b846d8dabdc64e7ea03552bad8f7fa74763fc67
/tests/lean/run/def_ite_value.lean
f31c2362fa5969622ca3d278c101f44ef303ab5e
[ "Apache-2.0" ]
permissive
pacchiano/lean
9324b33f3ac3b5c5647285160f9f6ea8d0d767dc
fdadada3a970377a6df8afcd629a6f2eab6e84e8
refs/heads/master
1,611,357,380,399
1,489,870,101,000
1,489,870,101,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
555
lean
inductive bv : nat → Type | nil : bv 0 | cons : Π n, bool → bv n → bv (n+1) open bv definition f : ∀ n : nat, bv n → nat → nat | (n+1) (cons .n b v) 1000000 := f n v 0 | (n+1) (cons .n b v) x := f n v (x + 1) | _ _ _ := 1 set_option pp.binder_types true #check @f._main.equations._eqn_1 #check @f._main.equations._eqn_2 #check @f._main.equations._eqn_3 example (n : nat) (b : bool) (v : bv n) (x : nat) : x ≠ 1000000 → f (n+1) (cons n b v) x = f n v (x + 1) := assume H, f._main.equations._eqn_3 n b v x H
eac3d82bb82d7a04daaf5a8dfac38341b92ad152
aa5a655c05e5359a70646b7154e7cac59f0b4132
/src/Lean/Elab/StructInst.lean
e2278a1d179f03f0c64ef85d4c9878d0939044e6
[ "Apache-2.0" ]
permissive
lambdaxymox/lean4
ae943c960a42247e06eff25c35338268d07454cb
278d47c77270664ef29715faab467feac8a0f446
refs/heads/master
1,677,891,867,340
1,612,500,005,000
1,612,500,005,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
34,163
lean
/- Copyright (c) 2020 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Util.FindExpr import Lean.Parser.Term import Lean.Elab.App import Lean.Elab.Binders namespace Lean.Elab.Term.StructInst open Std (HashMap) open Meta /- Structure instances are of the form: "{" >> optional (atomic (termParser >> " with ")) >> manyIndent (group (structInstField >> optional ", ")) >> optEllipsis >> optional (" : " >> termParser) >> " }" -/ @[builtinMacro Lean.Parser.Term.structInst] def expandStructInstExpectedType : Macro := fun stx => let expectedArg := stx[4] if expectedArg.isNone then Macro.throwUnsupported else let expected := expectedArg[1] let stxNew := stx.setArg 4 mkNullNode `(($stxNew : $expected)) /- If `stx` is of the form `{ s with ... }` and `s` is not a local variable, expand into `let src := s; { src with ... }`. Note that this one is not a `Macro` because we need to access the local context. -/ private def expandNonAtomicExplicitSource (stx : Syntax) : TermElabM (Option Syntax) := withFreshMacroScope do let sourceOpt := stx[1] if sourceOpt.isNone then pure none else let source := sourceOpt[0] match (← isLocalIdent? source) with | some _ => pure none | none => let src ← `(src) let sourceOpt := sourceOpt.setArg 0 src let stxNew := stx.setArg 1 sourceOpt `(let src := $source; $stxNew) inductive Source where | none -- structure instance source has not been provieded | implicit (stx : Syntax) -- `..` | explicit (stx : Syntax) (src : Expr) -- `src with` deriving Inhabited def Source.isNone : Source → Bool | Source.none => true | _ => false def setStructSourceSyntax (structStx : Syntax) : Source → Syntax | Source.none => (structStx.setArg 1 mkNullNode).setArg 3 mkNullNode | Source.implicit stx => (structStx.setArg 1 mkNullNode).setArg 3 stx | Source.explicit stx _ => (structStx.setArg 1 stx).setArg 3 mkNullNode private def getStructSource (stx : Syntax) : TermElabM Source := withRef stx do let explicitSource := stx[1] let implicitSource := stx[3] if explicitSource.isNone && implicitSource[0].isNone then return Source.none else if explicitSource.isNone then return Source.implicit implicitSource else if implicitSource[0].isNone then let fvar? ← isLocalIdent? explicitSource[0] match fvar? with | none => unreachable! -- expandNonAtomicExplicitSource must have been used when we get here | some src => return Source.explicit explicitSource src else throwError "invalid structure instance `with` and `..` cannot be used together" /- We say a `{ ... }` notation is a `modifyOp` if it contains only one ``` def structInstArrayRef := parser! "[" >> termParser >>"]" ``` -/ private def isModifyOp? (stx : Syntax) : TermElabM (Option Syntax) := do let s? ← stx[2].getArgs.foldlM (init := none) fun s? p => /- p is of the form `(group (structInstField >> optional ", "))` -/ let arg := p[0] /- Remark: the syntax for `structInstField` is ``` def structInstLVal := parser! (ident <|> numLit <|> structInstArrayRef) >> many (group ("." >> (ident <|> numLit)) <|> structInstArrayRef) def structInstField := parser! structInstLVal >> " := " >> termParser ``` -/ let lval := arg[0] let k := lval[0].getKind if k == `Lean.Parser.Term.structInstArrayRef then match s? with | none => pure (some arg) | some s => if s.getKind == `Lean.Parser.Term.structInstArrayRef then throwErrorAt arg "invalid {...} notation, at most one `[..]` at a given level" else throwErrorAt arg "invalid {...} notation, can't mix field and `[..]` at a given level" else match s? with | none => pure (some arg) | some s => if s.getKind == `Lean.Parser.Term.structInstArrayRef then throwErrorAt arg "invalid {...} notation, can't mix field and `[..]` at a given level" else pure s? match s? with | none => pure none | some s => if s[0][0].getKind == `Lean.Parser.Term.structInstArrayRef then pure s? else pure none private def elabModifyOp (stx modifyOp source : Syntax) (expectedType? : Option Expr) : TermElabM Expr := do let cont (val : Syntax) : TermElabM Expr := do let lval := modifyOp[0][0] let idx := lval[1] let self := source[0] let stxNew ← `($(self).modifyOp (idx := $idx) (fun s => $val)) trace[Elab.struct.modifyOp]! "{stx}\n===>\n{stxNew}" withMacroExpansion stx stxNew <| elabTerm stxNew expectedType? trace[Elab.struct.modifyOp]! "{modifyOp}\nSource: {source}" let rest := modifyOp[0][1] if rest.isNone then cont modifyOp[2] else let s ← `(s) let valFirst := rest[0] let valFirst := if valFirst.getKind == `Lean.Parser.Term.structInstArrayRef then valFirst else valFirst[1] let restArgs := rest.getArgs let valRest := mkNullNode restArgs[1:restArgs.size] let valField := modifyOp.setArg 0 <| Syntax.node ``Parser.Term.structInstLVal #[valFirst, valRest] let valSource := source.modifyArg 0 fun _ => s let val := stx.setArg 1 valSource let val := val.setArg 2 <| mkNullNode #[mkNullNode #[valField, mkNullNode]] trace[Elab.struct.modifyOp]! "{stx}\nval: {val}" cont val /- Get structure name and elaborate explicit source (if available) -/ private def getStructName (stx : Syntax) (expectedType? : Option Expr) (sourceView : Source) : TermElabM Name := do tryPostponeIfNoneOrMVar expectedType? let useSource : Unit → TermElabM Name := fun _ => match sourceView, expectedType? with | Source.explicit _ src, _ => do let srcType ← inferType src let srcType ← whnf srcType tryPostponeIfMVar srcType match srcType.getAppFn with | Expr.const constName _ _ => pure constName | _ => throwUnexpectedExpectedType srcType "source" | _, some expectedType => throwUnexpectedExpectedType expectedType | _, none => throwUnknownExpectedType match expectedType? with | none => useSource () | some expectedType => let expectedType ← whnf expectedType match expectedType.getAppFn with | Expr.const constName _ _ => pure constName | _ => useSource () where throwUnknownExpectedType := throwError! "invalid \{...} notation, expected type is not known" throwUnexpectedExpectedType type (kind := "expected") := do let type ← instantiateMVars type if type.getAppFn.isMVar then throwUnknownExpectedType else throwError! "invalid \{...} notation, {kind} type is not of the form (C ...){indentExpr type}" inductive FieldLHS where | fieldName (ref : Syntax) (name : Name) | fieldIndex (ref : Syntax) (idx : Nat) | modifyOp (ref : Syntax) (index : Syntax) deriving Inhabited instance : ToFormat FieldLHS := ⟨fun lhs => match lhs with | FieldLHS.fieldName _ n => fmt n | FieldLHS.fieldIndex _ i => fmt i | FieldLHS.modifyOp _ i => "[" ++ i.prettyPrint ++ "]"⟩ inductive FieldVal (σ : Type) where | term (stx : Syntax) : FieldVal σ | nested (s : σ) : FieldVal σ | default : FieldVal σ -- mark that field must be synthesized using default value deriving Inhabited structure Field (σ : Type) where ref : Syntax lhs : List FieldLHS val : FieldVal σ expr? : Option Expr := none deriving Inhabited def Field.isSimple {σ} : Field σ → Bool | { lhs := [_], .. } => true | _ => false inductive Struct where | mk (ref : Syntax) (structName : Name) (fields : List (Field Struct)) (source : Source) deriving Inhabited abbrev Fields := List (Field Struct) /- true if all fields of the given structure are marked as `default` -/ partial def Struct.allDefault : Struct → Bool | ⟨_, _, fields, _⟩ => fields.all fun ⟨_, _, val, _⟩ => match val with | FieldVal.term _ => false | FieldVal.default => true | FieldVal.nested s => allDefault s def Struct.ref : Struct → Syntax | ⟨ref, _, _, _⟩ => ref def Struct.structName : Struct → Name | ⟨_, structName, _, _⟩ => structName def Struct.fields : Struct → Fields | ⟨_, _, fields, _⟩ => fields def Struct.source : Struct → Source | ⟨_, _, _, s⟩ => s def formatField (formatStruct : Struct → Format) (field : Field Struct) : Format := Format.joinSep field.lhs " . " ++ " := " ++ match field.val with | FieldVal.term v => v.prettyPrint | FieldVal.nested s => formatStruct s | FieldVal.default => "<default>" partial def formatStruct : Struct → Format | ⟨_, structName, fields, source⟩ => let fieldsFmt := Format.joinSep (fields.map (formatField formatStruct)) ", " match source with | Source.none => "{" ++ fieldsFmt ++ "}" | Source.implicit _ => "{" ++ fieldsFmt ++ " .. }" | Source.explicit _ src => "{" ++ format src ++ " with " ++ fieldsFmt ++ "}" instance : ToFormat Struct := ⟨formatStruct⟩ instance : ToString Struct := ⟨toString ∘ format⟩ instance : ToFormat (Field Struct) := ⟨formatField formatStruct⟩ instance : ToString (Field Struct) := ⟨toString ∘ format⟩ /- Recall that `structInstField` elements have the form ``` def structInstField := parser! structInstLVal >> " := " >> termParser def structInstLVal := parser! (ident <|> numLit <|> structInstArrayRef) >> many (("." >> (ident <|> numLit)) <|> structInstArrayRef) def structInstArrayRef := parser! "[" >> termParser >>"]" ``` -/ -- Remark: this code relies on the fact that `expandStruct` only transforms `fieldLHS.fieldName` def FieldLHS.toSyntax (first : Bool) : FieldLHS → Syntax | FieldLHS.modifyOp stx _ => stx | FieldLHS.fieldName stx name => if first then mkIdentFrom stx name else mkNullNode #[mkAtomFrom stx ".", mkIdentFrom stx name] | FieldLHS.fieldIndex stx _ => if first then stx else mkNullNode #[mkAtomFrom stx ".", stx] def FieldVal.toSyntax : FieldVal Struct → Syntax | FieldVal.term stx => stx | _ => unreachable! def Field.toSyntax : Field Struct → Syntax | field => let stx := field.ref let stx := stx.setArg 2 field.val.toSyntax match field.lhs with | first::rest => stx.setArg 0 <| mkNullNode #[first.toSyntax true, mkNullNode <| rest.toArray.map (FieldLHS.toSyntax false) ] | _ => unreachable! private def toFieldLHS (stx : Syntax) : Except String FieldLHS := if stx.getKind == `Lean.Parser.Term.structInstArrayRef then return FieldLHS.modifyOp stx stx[1] else -- Note that the representation of the first field is different. let stx := if stx.getKind == nullKind then stx[1] else stx if stx.isIdent then return FieldLHS.fieldName stx stx.getId.eraseMacroScopes else match stx.isFieldIdx? with | some idx => return FieldLHS.fieldIndex stx idx | none => throw "unexpected structure syntax" private def mkStructView (stx : Syntax) (structName : Name) (source : Source) : Except String Struct := do /- Recall that `stx` is of the form ``` parser! "{" >> optional (atomic (termParser >> " with ")) >> manyIndent (group (structInstField >> optional ", ")) >> optional ".." >> optional (" : " >> termParser) >> " }" ``` -/ let fieldsStx := stx[2].getArgs.map (·[0]) let fields ← fieldsStx.toList.mapM fun fieldStx => do let val := fieldStx[2] let first ← toFieldLHS fieldStx[0][0] let rest ← fieldStx[0][1].getArgs.toList.mapM toFieldLHS pure { ref := fieldStx, lhs := first :: rest, val := FieldVal.term val : Field Struct } pure ⟨stx, structName, fields, source⟩ def Struct.modifyFieldsM {m : Type → Type} [Monad m] (s : Struct) (f : Fields → m Fields) : m Struct := match s with | ⟨ref, structName, fields, source⟩ => return ⟨ref, structName, (← f fields), source⟩ @[inline] def Struct.modifyFields (s : Struct) (f : Fields → Fields) : Struct := Id.run <| s.modifyFieldsM f def Struct.setFields (s : Struct) (fields : Fields) : Struct := s.modifyFields fun _ => fields private def expandCompositeFields (s : Struct) : Struct := s.modifyFields fun fields => fields.map fun field => match field with | { lhs := FieldLHS.fieldName ref (Name.str Name.anonymous _ _) :: rest, .. } => field | { lhs := FieldLHS.fieldName ref n@(Name.str _ _ _) :: rest, .. } => let newEntries := n.components.map <| FieldLHS.fieldName ref { field with lhs := newEntries ++ rest } | _ => field private def expandNumLitFields (s : Struct) : TermElabM Struct := s.modifyFieldsM fun fields => do let env ← getEnv let fieldNames := getStructureFields env s.structName fields.mapM fun field => match field with | { lhs := FieldLHS.fieldIndex ref idx :: rest, .. } => if idx == 0 then throwErrorAt ref "invalid field index, index must be greater than 0" else if idx > fieldNames.size then throwErrorAt! ref "invalid field index, structure has only #{fieldNames.size} fields" else pure { field with lhs := FieldLHS.fieldName ref fieldNames[idx - 1] :: rest } | _ => pure field /- For example, consider the following structures: ``` structure A where x : Nat structure B extends A where y : Nat structure C extends B where z : Bool ``` This method expands parent structure fields using the path to the parent structure. For example, ``` { x := 0, y := 0, z := true : C } ``` is expanded into ``` { toB.toA.x := 0, toB.y := 0, z := true : C } ``` -/ private def expandParentFields (s : Struct) : TermElabM Struct := do let env ← getEnv s.modifyFieldsM fun fields => fields.mapM fun field => match field with | { lhs := FieldLHS.fieldName ref fieldName :: rest, .. } => match findField? env s.structName fieldName with | none => throwErrorAt! ref "'{fieldName}' is not a field of structure '{s.structName}'" | some baseStructName => if baseStructName == s.structName then pure field else match getPathToBaseStructure? env baseStructName s.structName with | some path => do let path := path.map fun funName => match funName with | Name.str _ s _ => FieldLHS.fieldName ref (Name.mkSimple s) | _ => unreachable! pure { field with lhs := path ++ field.lhs } | _ => throwErrorAt! ref "failed to access field '{fieldName}' in parent structure" | _ => pure field private abbrev FieldMap := HashMap Name Fields private def mkFieldMap (fields : Fields) : TermElabM FieldMap := fields.foldlM (init := {}) fun fieldMap field => match field.lhs with | FieldLHS.fieldName _ fieldName :: rest => match fieldMap.find? fieldName with | some (prevField::restFields) => if field.isSimple || prevField.isSimple then throwErrorAt! field.ref "field '{fieldName}' has already beed specified" else return fieldMap.insert fieldName (field::prevField::restFields) | _ => return fieldMap.insert fieldName [field] | _ => unreachable! private def isSimpleField? : Fields → Option (Field Struct) | [field] => if field.isSimple then some field else none | _ => none private def getFieldIdx (structName : Name) (fieldNames : Array Name) (fieldName : Name) : TermElabM Nat := do match fieldNames.findIdx? fun n => n == fieldName with | some idx => pure idx | none => throwError! "field '{fieldName}' is not a valid field of '{structName}'" private def mkProjStx (s : Syntax) (fieldName : Name) : Syntax := Syntax.node `Lean.Parser.Term.proj #[s, mkAtomFrom s ".", mkIdentFrom s fieldName] private def mkSubstructSource (structName : Name) (fieldNames : Array Name) (fieldName : Name) (src : Source) : TermElabM Source := match src with | Source.explicit stx src => do let idx ← getFieldIdx structName fieldNames fieldName let stx := stx.modifyArg 0 fun stx => mkProjStx stx fieldName return Source.explicit stx (mkProj structName idx src) | s => return s @[specialize] private def groupFields (expandStruct : Struct → TermElabM Struct) (s : Struct) : TermElabM Struct := do let env ← getEnv let fieldNames := getStructureFields env s.structName withRef s.ref do s.modifyFieldsM fun fields => do let fieldMap ← mkFieldMap fields fieldMap.toList.mapM fun ⟨fieldName, fields⟩ => do match isSimpleField? fields with | some field => pure field | none => let substructFields := fields.map fun field => { field with lhs := field.lhs.tail! } let substructSource ← mkSubstructSource s.structName fieldNames fieldName s.source let field := fields.head! match Lean.isSubobjectField? env s.structName fieldName with | some substructName => let substruct := Struct.mk s.ref substructName substructFields substructSource let substruct ← expandStruct substruct pure { field with lhs := [field.lhs.head!], val := FieldVal.nested substruct } | none => do -- It is not a substructure field. Thus, we wrap fields using `Syntax`, and use `elabTerm` to process them. let valStx := s.ref -- construct substructure syntax using s.ref as template let valStx := valStx.setArg 4 mkNullNode -- erase optional expected type let args := substructFields.toArray.map fun field => mkNullNode #[field.toSyntax, mkNullNode] let valStx := valStx.setArg 2 (mkNullNode args) let valStx := setStructSourceSyntax valStx substructSource pure { field with lhs := [field.lhs.head!], val := FieldVal.term valStx } def findField? (fields : Fields) (fieldName : Name) : Option (Field Struct) := fields.find? fun field => match field.lhs with | [FieldLHS.fieldName _ n] => n == fieldName | _ => false @[specialize] private def addMissingFields (expandStruct : Struct → TermElabM Struct) (s : Struct) : TermElabM Struct := do let env ← getEnv let fieldNames := getStructureFields env s.structName let ref := s.ref withRef ref do let fields ← fieldNames.foldlM (init := []) fun fields fieldName => do match findField? s.fields fieldName with | some field => return field::fields | none => let addField (val : FieldVal Struct) : TermElabM Fields := do return { ref := s.ref, lhs := [FieldLHS.fieldName s.ref fieldName], val := val } :: fields match Lean.isSubobjectField? env s.structName fieldName with | some substructName => do let substructSource ← mkSubstructSource s.structName fieldNames fieldName s.source let substruct := Struct.mk s.ref substructName [] substructSource let substruct ← expandStruct substruct addField (FieldVal.nested substruct) | none => match s.source with | Source.none => addField FieldVal.default | Source.implicit _ => addField (FieldVal.term (mkHole s.ref)) | Source.explicit stx _ => -- stx is of the form `optional (try (termParser >> "with"))` let src := stx[0] let val := mkProjStx src fieldName addField (FieldVal.term val) return s.setFields fields.reverse private partial def expandStruct (s : Struct) : TermElabM Struct := do let s := expandCompositeFields s let s ← expandNumLitFields s let s ← expandParentFields s let s ← groupFields expandStruct s addMissingFields expandStruct s structure CtorHeaderResult where ctorFn : Expr ctorFnType : Expr instMVars : Array MVarId := #[] private def mkCtorHeaderAux : Nat → Expr → Expr → Array MVarId → TermElabM CtorHeaderResult | 0, type, ctorFn, instMVars => pure { ctorFn := ctorFn, ctorFnType := type, instMVars := instMVars } | n+1, type, ctorFn, instMVars => do let type ← whnfForall type match type with | Expr.forallE _ d b c => match c.binderInfo with | BinderInfo.instImplicit => let a ← mkFreshExprMVar d MetavarKind.synthetic mkCtorHeaderAux n (b.instantiate1 a) (mkApp ctorFn a) (instMVars.push a.mvarId!) | _ => let a ← mkFreshExprMVar d mkCtorHeaderAux n (b.instantiate1 a) (mkApp ctorFn a) instMVars | _ => throwError "unexpected constructor type" private partial def getForallBody : Nat → Expr → Option Expr | i+1, Expr.forallE _ _ b _ => getForallBody i b | i+1, _ => none | 0, type => type private def propagateExpectedType (type : Expr) (numFields : Nat) (expectedType? : Option Expr) : TermElabM Unit := match expectedType? with | none => pure () | some expectedType => do match getForallBody numFields type with | none => pure () | some typeBody => unless typeBody.hasLooseBVars do discard <| isDefEq expectedType typeBody private def mkCtorHeader (ctorVal : ConstructorVal) (expectedType? : Option Expr) : TermElabM CtorHeaderResult := do let us ← ctorVal.levelParams.mapM fun _ => mkFreshLevelMVar let val := Lean.mkConst ctorVal.name us let type := (ConstantInfo.ctorInfo ctorVal).instantiateTypeLevelParams us let r ← mkCtorHeaderAux ctorVal.numParams type val #[] propagateExpectedType r.ctorFnType ctorVal.numFields expectedType? synthesizeAppInstMVars r.instMVars pure r def markDefaultMissing (e : Expr) : Expr := mkAnnotation `structInstDefault e def defaultMissing? (e : Expr) : Option Expr := annotation? `structInstDefault e def throwFailedToElabField {α} (fieldName : Name) (structName : Name) (msgData : MessageData) : TermElabM α := throwError! "failed to elaborate field '{fieldName}' of '{structName}, {msgData}" def trySynthStructInstance? (s : Struct) (expectedType : Expr) : TermElabM (Option Expr) := do if !s.allDefault then pure none else try synthInstance? expectedType catch _ => pure none private partial def elabStruct (s : Struct) (expectedType? : Option Expr) : TermElabM (Expr × Struct) := withRef s.ref do let env ← getEnv let ctorVal := getStructureCtor env s.structName let { ctorFn := ctorFn, ctorFnType := ctorFnType, .. } ← mkCtorHeader ctorVal expectedType? let (e, _, fields) ← s.fields.foldlM (init := (ctorFn, ctorFnType, [])) fun (e, type, fields) field => match field.lhs with | [FieldLHS.fieldName ref fieldName] => do let type ← whnfForall type match type with | Expr.forallE _ d b c => let cont (val : Expr) (field : Field Struct) : TermElabM (Expr × Expr × Fields) := do pushInfoTree <| InfoTree.node (children := {}) <| Info.ofFieldInfo { lctx := (← getLCtx), val := val, name := fieldName, stx := ref } let e := mkApp e val let type := b.instantiate1 val let field := { field with expr? := some val } pure (e, type, field::fields) match field.val with | FieldVal.term stx => cont (← elabTermEnsuringType stx d) field | FieldVal.nested s => do -- if all fields of `s` are marked as `default`, then try to synthesize instance match (← trySynthStructInstance? s d) with | some val => cont val { field with val := FieldVal.term (mkHole field.ref) } | none => do let (val, sNew) ← elabStruct s (some d); let val ← ensureHasType d val; cont val { field with val := FieldVal.nested sNew } | FieldVal.default => do let val ← withRef field.ref <| mkFreshExprMVar (some d); cont (markDefaultMissing val) field | _ => withRef field.ref <| throwFailedToElabField fieldName s.structName m!"unexpected constructor type{indentExpr type}" | _ => throwErrorAt field.ref "unexpected unexpanded structure field" pure (e, s.setFields fields.reverse) namespace DefaultFields structure Context where -- We must search for default values overriden in derived structures structs : Array Struct := #[] allStructNames : Array Name := #[] /-- Consider the following example: ``` structure A where x : Nat := 1 structure B extends A where y : Nat := x + 1 x := y + 1 structure C extends B where z : Nat := 2*y x := z + 3 ``` And we are trying to elaborate a structure instance for `C`. There are default values for `x` at `A`, `B`, and `C`. We say the default value at `C` has distance 0, the one at `B` distance 1, and the one at `A` distance 2. The field `maxDistance` specifies the maximum distance considered in a round of Default field computation. Remark: since `C` does not set a default value of `y`, the default value at `B` is at distance 0. The fixpoint for setting default values works in the following way. - Keep computing default values using `maxDistance == 0`. - We increase `maxDistance` whenever we failed to compute a new default value in a round. - If `maxDistance > 0`, then we interrupt a round as soon as we compute some default value. We use depth-first search. - We sign an error if no progress is made when `maxDistance` == structure hierarchy depth (2 in the example above). -/ maxDistance : Nat := 0 structure State where progress : Bool := false partial def collectStructNames (struct : Struct) (names : Array Name) : Array Name := let names := names.push struct.structName struct.fields.foldl (init := names) fun names field => match field.val with | FieldVal.nested struct => collectStructNames struct names | _ => names partial def getHierarchyDepth (struct : Struct) : Nat := struct.fields.foldl (init := 0) fun max field => match field.val with | FieldVal.nested struct => Nat.max max (getHierarchyDepth struct + 1) | _ => max partial def findDefaultMissing? (mctx : MetavarContext) (struct : Struct) : Option (Field Struct) := struct.fields.findSome? fun field => match field.val with | FieldVal.nested struct => findDefaultMissing? mctx struct | _ => match field.expr? with | none => unreachable! | some expr => match defaultMissing? expr with | some (Expr.mvar mvarId _) => if mctx.isExprAssigned mvarId then none else some field | _ => none def getFieldName (field : Field Struct) : Name := match field.lhs with | [FieldLHS.fieldName _ fieldName] => fieldName | _ => unreachable! abbrev M := ReaderT Context (StateRefT State TermElabM) def isRoundDone : M Bool := do return (← get).progress && (← read).maxDistance > 0 def getFieldValue? (struct : Struct) (fieldName : Name) : Option Expr := struct.fields.findSome? fun field => if getFieldName field == fieldName then field.expr? else none partial def mkDefaultValueAux? (struct : Struct) : Expr → TermElabM (Option Expr) | Expr.lam n d b c => withRef struct.ref do if c.binderInfo.isExplicit then let fieldName := n match getFieldValue? struct fieldName with | none => pure none | some val => let valType ← inferType val if (← isDefEq valType d) then mkDefaultValueAux? struct (b.instantiate1 val) else pure none else let arg ← mkFreshExprMVar d mkDefaultValueAux? struct (b.instantiate1 arg) | e => if e.isAppOfArity `id 2 then pure (some e.appArg!) else pure (some e) def mkDefaultValue? (struct : Struct) (cinfo : ConstantInfo) : TermElabM (Option Expr) := withRef struct.ref do let us ← cinfo.lparams.mapM fun _ => mkFreshLevelMVar mkDefaultValueAux? struct (cinfo.instantiateValueLevelParams us) /-- If `e` is a projection function of one of the given structures, then reduce it -/ def reduceProjOf? (structNames : Array Name) (e : Expr) : MetaM (Option Expr) := do if !e.isApp then pure none else match e.getAppFn with | Expr.const name _ _ => do let env ← getEnv match env.getProjectionStructureName? name with | some structName => if structNames.contains structName then Meta.unfoldDefinition? e else pure none | none => pure none | _ => pure none /-- Reduce default value. It performs beta reduction and projections of the given structures. -/ partial def reduce (structNames : Array Name) : Expr → MetaM Expr | e@(Expr.lam _ _ _ _) => lambdaLetTelescope e fun xs b => do mkLambdaFVars xs (← reduce structNames b) | e@(Expr.forallE _ _ _ _) => forallTelescope e fun xs b => do mkForallFVars xs (← reduce structNames b) | e@(Expr.letE _ _ _ _ _) => lambdaLetTelescope e fun xs b => do mkLetFVars xs (← reduce structNames b) | e@(Expr.proj _ i b _) => do match (← Meta.project? b i) with | some r => reduce structNames r | none => return e.updateProj! (← reduce structNames b) | e@(Expr.app f _ _) => do match (← reduceProjOf? structNames e) with | some r => reduce structNames r | none => let f := f.getAppFn let f' ← reduce structNames f if f'.isLambda then let revArgs := e.getAppRevArgs reduce structNames (f'.betaRev revArgs) else let args ← e.getAppArgs.mapM (reduce structNames) return (mkAppN f' args) | e@(Expr.mdata _ b _) => do let b ← reduce structNames b if (defaultMissing? e).isSome && !b.isMVar then return b else return e.updateMData! b | e@(Expr.mvar mvarId _) => do match (← getExprMVarAssignment? mvarId) with | some val => if val.isMVar then reduce structNames val else pure val | none => return e | e => return e partial def tryToSynthesizeDefault (structs : Array Struct) (allStructNames : Array Name) (maxDistance : Nat) (fieldName : Name) (mvarId : MVarId) : TermElabM Bool := let rec loop (i : Nat) (dist : Nat) := do if dist > maxDistance then pure false else if h : i < structs.size then do let struct := structs.get ⟨i, h⟩ let defaultName := struct.structName ++ fieldName ++ `_default let env ← getEnv match env.find? defaultName with | some cinfo@(ConstantInfo.defnInfo defVal) => do let mctx ← getMCtx let val? ← mkDefaultValue? struct cinfo match val? with | none => do setMCtx mctx; loop (i+1) (dist+1) | some val => do let val ← reduce allStructNames val match val.find? fun e => (defaultMissing? e).isSome with | some _ => setMCtx mctx; loop (i+1) (dist+1) | none => let mvarDecl ← getMVarDecl mvarId let val ← ensureHasType mvarDecl.type val assignExprMVar mvarId val pure true | _ => loop (i+1) dist else pure false loop 0 0 partial def step (struct : Struct) : M Unit := unless (← isRoundDone) do withReader (fun ctx => { ctx with structs := ctx.structs.push struct }) do for field in struct.fields do match field.val with | FieldVal.nested struct => step struct | _ => match field.expr? with | none => unreachable! | some expr => match defaultMissing? expr with | some (Expr.mvar mvarId _) => unless (← isExprMVarAssigned mvarId) do let ctx ← read if (← withRef field.ref <| tryToSynthesizeDefault ctx.structs ctx.allStructNames ctx.maxDistance (getFieldName field) mvarId) then modify fun s => { s with progress := true } | _ => pure () partial def propagateLoop (hierarchyDepth : Nat) (d : Nat) (struct : Struct) : M Unit := do match findDefaultMissing? (← getMCtx) struct with | none => pure () -- Done | some field => if d > hierarchyDepth then throwErrorAt! field.ref "field '{getFieldName field}' is missing" else withReader (fun ctx => { ctx with maxDistance := d }) do modify fun s => { s with progress := false } step struct if (← get).progress then do propagateLoop hierarchyDepth 0 struct else propagateLoop hierarchyDepth (d+1) struct def propagate (struct : Struct) : TermElabM Unit := let hierarchyDepth := getHierarchyDepth struct let structNames := collectStructNames struct #[] (propagateLoop hierarchyDepth 0 struct { allStructNames := structNames }).run' {} end DefaultFields private def elabStructInstAux (stx : Syntax) (expectedType? : Option Expr) (source : Source) : TermElabM Expr := do let structName ← getStructName stx expectedType? source unless isStructureLike (← getEnv) structName do throwError! "invalid \{...} notation, '{structName}' is not a structure" match mkStructView stx structName source with | Except.error ex => throwError ex | Except.ok struct => let struct ← expandStruct struct trace[Elab.struct]! "{struct}" let (r, struct) ← elabStruct struct expectedType? DefaultFields.propagate struct pure r @[builtinTermElab structInst] def elabStructInst : TermElab := fun stx expectedType? => do match (← expandNonAtomicExplicitSource stx) with | some stxNew => withMacroExpansion stx stxNew <| elabTerm stxNew expectedType? | none => let sourceView ← getStructSource stx match (← isModifyOp? stx), sourceView with | some modifyOp, Source.explicit source _ => elabModifyOp stx modifyOp source expectedType? | some _, _ => throwError "invalid {...} notation, explicit source is required when using '[<index>] := <value>'" | _, _ => elabStructInstAux stx expectedType? sourceView builtin_initialize registerTraceClass `Elab.struct end Lean.Elab.Term.StructInst
9ee241e91ff1a6d044c9c245ec8b2d2693592c26
32da3d0f92cab08875472ef6cacc1931c2b3eafa
/src/measure_theory/lp_space.lean
ce27cf372f1f8ebb087b6f37341a3994b4bb0c02
[ "Apache-2.0" ]
permissive
karthiknadig/mathlib
b6073c3748860bfc9a3e55da86afcddba62dc913
33a86cfff12d7f200d0010cd03b95e9b69a6c1a5
refs/heads/master
1,676,389,371,851
1,610,061,127,000
1,610,061,127,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
12,003
lean
/- Copyright (c) 2020 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Rémy Degenne. -/ import measure_theory.l1_space import analysis.mean_inequalities /-! # ℒp space This file describes properties of measurable functions with finite seminorm `(∫ ∥f a∥^p ∂μ) ^ (1/p)` for `p:ℝ` with `1 ≤ p`. ## Main definitions * `mem_ℒp f p μ` : the function `f` has finite p-seminorm for measure `μ`, for `p:ℝ` such that `hp1 : 1 ≤ p`, ## Notation * `snorm f p μ` : `(∫ ∥f a∥^p ∂μ) ^ (1/p)` for `f : α → F`, where `α` is a measurable space and `F` is a normed group. -/ open measure_theory noncomputable theory namespace ℒp_space variables {α E F : Type*} [measurable_space α] {μ : measure α} [measurable_space E] [normed_group E] [normed_group F] {p : ℝ} section ℒp_space_definition /-- The property that `f:α→E` is measurable and `∫ ∥f a∥^p ∂μ` is finite -/ def mem_ℒp (f : α → E) (p : ℝ) (μ : measure α) : Prop := ae_measurable f μ ∧ ∫⁻ a, (nnnorm (f a)) ^ p ∂μ < ⊤ /-- `(∫ ∥f a∥^p ∂μ) ^ (1/p)`, which is a seminorm on the space of measurable functions for which this quantity is finite -/ def snorm (f : α → F) (p : ℝ) (μ : measure α) : ennreal := (∫⁻ a, (nnnorm (f a))^p ∂μ) ^ (1/p) lemma lintegral_rpow_nnnorm_eq_rpow_snorm {f : α → F} (hp0_lt : 0 < p) : ∫⁻ a, (nnnorm (f a)) ^ p ∂μ = (snorm f p μ) ^ p := begin rw [snorm, ←ennreal.rpow_mul, one_div, inv_mul_cancel, ennreal.rpow_one], exact (ne_of_lt hp0_lt).symm, end end ℒp_space_definition lemma mem_ℒp_one_iff_integrable {f : α → E} : mem_ℒp f 1 μ ↔ integrable f μ := by simp only [integrable, has_finite_integral, mem_ℒp, ennreal.rpow_one, nnreal.coe_one] section top lemma mem_ℒp.snorm_lt_top {f : α → E} (hp0 : 0 ≤ p) (hfp : mem_ℒp f p μ) : snorm f p μ < ⊤ := begin refine ennreal.rpow_lt_top_of_nonneg _ (ne_of_lt hfp.right), rw [one_div, inv_nonneg], exact hp0, end lemma mem_ℒp.snorm_ne_top {f : α → E} (hp0 : 0 ≤ p) (hfp : mem_ℒp f p μ) : snorm f p μ ≠ ⊤ := ne_of_lt (hfp.snorm_lt_top hp0) lemma lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top {f : α → F} (hp0_lt : 0 < p) (hfp : snorm f p μ < ⊤) : ∫⁻ a, (nnnorm (f a)) ^ p ∂μ < ⊤ := begin rw lintegral_rpow_nnnorm_eq_rpow_snorm hp0_lt, exact ennreal.rpow_lt_top_of_nonneg (le_of_lt hp0_lt) (ne_of_lt hfp), end lemma mem_ℒp_of_snorm_lt_top {f : α → E} (hp0_lt : 0 < p) (hfm : ae_measurable f μ) (hfp : snorm f p μ < ⊤) : mem_ℒp f p μ := ⟨hfm, lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top hp0_lt hfp⟩ end top section zero lemma zero_mem_ℒp (hp0_lt : 0 < p) : mem_ℒp (0 : α → E) p μ := ⟨measurable_zero.ae_measurable, by simp [hp0_lt]⟩ @[simp] lemma snorm_zero (hp0_lt : 0 < p) : snorm (0 : α → F) p μ = 0 := by simp [snorm, hp0_lt] /-- When `μ = 0`, we have `∫ f^p ∂μ = 0`. `snorm f p μ` is then `0`, `1` or `⊤` depending on `p`. -/ lemma snorm_measure_zero_of_pos {f : α → F} (hp_pos : 0 < p) : snorm f p 0 = 0 := by simp [snorm, hp_pos] /-- When `μ = 0`, we have `∫ f^p ∂μ = 0`. `snorm f p μ` is then `0`, `1` or `⊤` depending on `p`. -/ lemma snorm_measure_zero_of_exponent_zero {f : α → F} : snorm f 0 0 = 1 := by simp [snorm] /-- When `μ = 0`, we have `∫ f^p ∂μ = 0`. `snorm f p μ` is then `0`, `1` or `⊤` depending on `p`. -/ lemma snorm_measure_zero_of_neg {f : α → F} (hp_neg : p < 0) : snorm f p 0 = ⊤ := by simp [snorm, hp_neg] end zero @[simp] lemma snorm_neg {f : α → F} : snorm (-f) p μ = snorm f p μ := by simp [snorm] section opens_measurable_space variable [opens_measurable_space E] lemma snorm_eq_zero_of_ae_zero {f : α → E} (hp0_lt : 0 < p) (hf : measurable f) (hf_zero : f =ᵐ[μ] 0) : snorm f p μ = 0 := begin rw [snorm, ennreal.rpow_eq_zero_iff], left, split, { rw lintegral_eq_zero_iff hf.nnnorm.ennreal_coe.ennreal_rpow_const, refine filter.eventually.mp hf_zero (filter.eventually_of_forall (λ x hx, _)), simp_rw ennreal.coe_rpow_of_nonneg _ (le_of_lt hp0_lt), simpa [pi.zero_apply, hx, (ne_of_lt hp0_lt).symm] using hx, }, { rwa [one_div, inv_pos], }, end lemma snorm_eq_zero_of_ae_zero' (hp0_ne : p ≠ 0) (hμ : μ ≠ 0) {f : α → E} (hf : measurable f) (hf_zero : f =ᵐ[μ] 0) : snorm f p μ = 0 := begin cases le_or_lt 0 p with hp0 hp_neg, { exact snorm_eq_zero_of_ae_zero (lt_of_le_of_ne hp0 hp0_ne.symm) hf hf_zero, }, { rw [snorm, ennreal.rpow_eq_zero_iff], right, split, { have h_lintegral_const : ∫⁻ (a : α), ↑(nnnorm (f a)) ^ p ∂μ = ∫⁻ (a : α), ⊤ ∂μ, { refine lintegral_congr_ae _, refine filter.eventually.mp hf_zero (filter.eventually_of_forall (λ x hx, _)), rw pi.zero_apply at hx, simp [hx, hp_neg], }, rw [h_lintegral_const], simp [hμ], }, { simp [hp_neg], },}, end lemma ae_eq_zero_of_snorm_eq_zero {f : α → E} (hp0 : 0 ≤ p) (hf : measurable f) (h : snorm f p μ = 0) : f =ᵐ[μ] 0 := begin rw [snorm, ennreal.rpow_eq_zero_iff] at h, cases h, { rw lintegral_eq_zero_iff hf.nnnorm.ennreal_coe.ennreal_rpow_const at h, refine filter.eventually.mp h.left (filter.eventually_of_forall (λ 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, }, { exfalso, exact ennreal.coe_ne_top hx.left, }, }, { exfalso, rw [one_div, inv_lt_zero] at h, linarith, }, end lemma snorm_eq_zero_iff (hp0_lt : 0 < p) {f : α → E} (hf : measurable f) : snorm f p μ = 0 ↔ f =ᵐ[μ] 0 := ⟨ae_eq_zero_of_snorm_eq_zero (le_of_lt hp0_lt) hf, snorm_eq_zero_of_ae_zero hp0_lt hf⟩ end opens_measurable_space 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) (μ : measure α) {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 : ennreal), 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.nnnorm.ennreal_coe ae_measurable_const ... = (∫⁻ (a : α), ↑(nnnorm (f a)) ^ q ∂μ) ^ (1/q) * μ set.univ ^ (1/p - 1/q) : by simp [hpqr], end lemma snorm_le_snorm_of_exponent_le {p q : ℝ} (hp0_lt : 0 < p) (hpq : p ≤ q) (μ : measure α) [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 mem_ℒp.mem_ℒp_of_exponent_le {p q : ℝ} {μ : measure α} [finite_measure μ] {f : α → E} (hfq : mem_ℒp f q μ) (hp_pos : 0 < p) (hpq : p ≤ q) : mem_ℒp f p μ := begin cases hfq with hfq_m hfq_lt_top, split, { exact hfq_m, }, have hq_pos : 0 < q, from lt_of_lt_of_le hp_pos hpq, suffices h_snorm : snorm f p μ < ⊤, { have h_top_eq : (⊤ : ennreal) = ⊤ ^ (1/p), by simp [hp_pos], rw [snorm, h_top_eq] at h_snorm, have h_snorm_pow : ((∫⁻ (a : α), ↑(nnnorm (f a)) ^ p ∂μ) ^ (1/p)) ^ p < (⊤ ^ (1/p)) ^ p, from ennreal.rpow_lt_rpow h_snorm hp_pos, rw [←ennreal.rpow_mul, ←ennreal.rpow_mul] at h_snorm_pow, simpa [(ne_of_lt hp_pos).symm] using h_snorm_pow, }, calc snorm f p μ ≤ snorm f q μ * (μ set.univ) ^ (1/p - 1/q) : snorm_le_snorm_mul_rpow_measure_univ hp_pos hpq μ hfq_m ... < ⊤ : begin rw ennreal.mul_lt_top_iff, left, split, { exact mem_ℒp.snorm_lt_top (le_of_lt hq_pos) ⟨hfq_m, hfq_lt_top⟩, }, { refine 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.integrable (hp1 : 1 ≤ p) {f : α → E} [finite_measure μ] (hfp : mem_ℒp f p μ) : integrable f μ := begin rw ←mem_ℒp_one_iff_integrable, exact hfp.mem_ℒp_of_exponent_le zero_lt_one hp1, 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 μ := calc (∫⁻ a, ↑(nnnorm ((f + g) a)) ^ p ∂μ) ^ (1 / p) ≤ (∫⁻ a, (((λ a, (nnnorm (f a) : ennreal)) + (λ a, (nnnorm (g a) : ennreal))) a) ^ p ∂μ) ^ (1 / p) : begin refine @ennreal.rpow_le_rpow _ _ (1/p) _ (by simp [le_trans zero_le_one hp1]), refine lintegral_mono (λ a, ennreal.rpow_le_rpow _ (le_trans zero_le_one hp1)), simp [←ennreal.coe_add, nnnorm_add_le], end ... ≤ snorm f p μ + snorm g p μ : ennreal.lintegral_Lp_add_le hf.nnnorm.ennreal_coe hg.nnnorm.ennreal_coe hp1 section second_countable_topology variable [topological_space.second_countable_topology E] lemma mem_ℒp.add {f g : α → E} (hf : mem_ℒp f p μ) (hg : mem_ℒp g p μ) (hp1 : 1 ≤ p) : mem_ℒp (f+g) p μ := begin have hp0_lt : 0 < p, from lt_of_lt_of_le zero_lt_one hp1, have hp0 : 0 ≤ p, from le_of_lt hp0_lt, split, { exact ae_measurable.add hf.1 hg.1, }, simp_rw [pi.add_apply, ennreal.coe_rpow_of_nonneg _ hp0], have h_nnnorm_add_le : ∫⁻ (a : α), ↑(nnnorm (f a + g a) ^ p) ∂μ ≤ ∫⁻ a, ↑((nnnorm (f a) + nnnorm (g a)) ^ p) ∂μ, { refine lintegral_mono_nnreal (λ a, _), exact nnreal.rpow_le_rpow (nnnorm_add_le (f a) (g a)) (le_of_lt hp0_lt), }, refine lt_of_le_of_lt h_nnnorm_add_le _, simp_rw [←ennreal.coe_rpow_of_nonneg _ hp0, ennreal.coe_add], let f_nnnorm := (λ a : α, (nnnorm (f a) : ennreal)), let g_nnnorm := (λ a : α, (nnnorm (g a) : ennreal)), change ∫⁻ (a : α), ((f_nnnorm + g_nnnorm) a) ^ p ∂μ < ⊤, exact ennreal.lintegral_rpow_add_lt_top_of_lintegral_rpow_lt_top hf.1.nnnorm.ennreal_coe hf.2 hg.1.nnnorm.ennreal_coe hg.2 hp1, end end second_countable_topology section normed_space variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 E] lemma mem_ℒp.const_smul {f : α → E} (hfp : mem_ℒp f p μ) (c : 𝕜) (hp0 : 0 ≤ p) : mem_ℒp (c • f) p μ := begin split, { exact ae_measurable.const_smul hfp.1 c, }, simp_rw [pi.smul_apply, nnnorm_smul, ennreal.coe_mul, ennreal.mul_rpow_of_nonneg _ _ hp0], rw lintegral_const_mul'' _ hfp.1.nnnorm.ennreal_coe.ennreal_rpow_const, exact ennreal.mul_lt_top (ennreal.rpow_lt_top_of_nonneg hp0 ennreal.coe_ne_top) hfp.2, end lemma snorm_smul_le_mul_snorm [measurable_space 𝕜] [opens_measurable_space 𝕜] {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 rw snorm, simp_rw [pi.smul_apply', nnnorm_smul, ennreal.coe_mul], exact ennreal.lintegral_Lp_mul_le_Lq_mul_Lr hp0_lt hpq hpqr μ hφ.nnnorm.ennreal_coe hf.nnnorm.ennreal_coe, end end normed_space end borel_space end ℒp_space
a227de8a20fd81717b4fdcea7ce94b28017527cb
bbecf0f1968d1fba4124103e4f6b55251d08e9c4
/src/analysis/asymptotics/asymptotics.lean
af3b5e28b0dac946bc2bc88b95fcde715306498b
[ "Apache-2.0" ]
permissive
waynemunro/mathlib
e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552
065a70810b5480d584033f7bbf8e0409480c2118
refs/heads/master
1,693,417,182,397
1,634,644,781,000
1,634,644,781,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
61,422
lean
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Yury Kudryashov -/ import analysis.normed_space.basic import topology.local_homeomorph /-! # Asymptotics We introduce these relations: * `is_O_with c f g l` : "f is big O of g along l with constant c"; * `is_O f g l` : "f is big O of g along l"; * `is_o f g l` : "f is little o of g along l". Here `l` is any filter on the domain of `f` and `g`, which are assumed to be the same. The codomains of `f` and `g` do not need to be the same; all that is needed that there is a norm associated with these types, and it is the norm that is compared asymptotically. The relation `is_O_with c` is introduced to factor out common algebraic arguments in the proofs of similar properties of `is_O` and `is_o`. Usually proofs outside of this file should use `is_O` instead. Often the ranges of `f` and `g` will be the real numbers, in which case the norm is the absolute value. In general, we have `is_O f g l ↔ is_O (λ x, ∥f x∥) (λ x, ∥g x∥) l`, and similarly for `is_o`. But our setup allows us to use the notions e.g. with functions to the integers, rationals, complex numbers, or any normed vector space without mentioning the norm explicitly. If `f` and `g` are functions to a normed field like the reals or complex numbers and `g` is always nonzero, we have `is_o f g l ↔ tendsto (λ x, f x / (g x)) l (𝓝 0)`. In fact, the right-to-left direction holds without the hypothesis on `g`, and in the other direction it suffices to assume that `f` is zero wherever `g` is. (This generalization is useful in defining the Fréchet derivative.) -/ open filter set open_locale topological_space big_operators classical filter nnreal namespace asymptotics variables {α : Type*} {β : Type*} {E : Type*} {F : Type*} {G : Type*} {E' : Type*} {F' : Type*} {G' : Type*} {R : Type*} {R' : Type*} {𝕜 : Type*} {𝕜' : Type*} variables [has_norm E] [has_norm F] [has_norm G] [normed_group E'] [normed_group F'] [normed_group G'] [normed_ring R] [normed_ring R'] [normed_field 𝕜] [normed_field 𝕜'] {c c' : ℝ} {f : α → E} {g : α → F} {k : α → G} {f' : α → E'} {g' : α → F'} {k' : α → G'} {l l' : filter α} section defs /-! ### Definitions -/ /-- This version of the Landau notation `is_O_with C f g l` where `f` and `g` are two functions on a type `α` and `l` is a filter on `α`, means that eventually for `l`, `∥f∥` is bounded by `C * ∥g∥`. In other words, `∥f∥ / ∥g∥` is eventually bounded by `C`, modulo division by zero issues that are avoided by this definition. Probably you want to use `is_O` instead of this relation. -/ @[irreducible] def is_O_with (c : ℝ) (f : α → E) (g : α → F) (l : filter α) : Prop := ∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥ /-- Definition of `is_O_with`. We record it in a lemma as we will set `is_O_with` to be irreducible at the end of this file. -/ lemma is_O_with_iff {c : ℝ} {f : α → E} {g : α → F} {l : filter α} : is_O_with c f g l ↔ ∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥ := by rw is_O_with alias is_O_with_iff ↔ asymptotics.is_O_with.bound asymptotics.is_O_with.of_bound /-- The Landau notation `is_O f g l` where `f` and `g` are two functions on a type `α` and `l` is a filter on `α`, means that eventually for `l`, `∥f∥` is bounded by a constant multiple of `∥g∥`. In other words, `∥f∥ / ∥g∥` is eventually bounded, modulo division by zero issues that are avoided by this definition. -/ @[irreducible] def is_O (f : α → E) (g : α → F) (l : filter α) : Prop := ∃ c : ℝ, is_O_with c f g l /-- Definition of `is_O` in terms of `is_O_with`. We record it in a lemma as we will set `is_O` to be irreducible at the end of this file. -/ lemma is_O_iff_is_O_with {f : α → E} {g : α → F} {l : filter α} : is_O f g l ↔ ∃ c : ℝ, is_O_with c f g l := by rw is_O /-- Definition of `is_O` in terms of filters. We record it in a lemma as we will set `is_O` to be irreducible at the end of this file. -/ lemma is_O_iff {f : α → E} {g : α → F} {l : filter α} : is_O f g l ↔ ∃ c : ℝ, ∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥ := by simp [is_O, is_O_with] lemma is_O.of_bound (c : ℝ) {f : α → E} {g : α → F} {l : filter α} (h : ∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥) : is_O f g l := is_O_iff.2 ⟨c, h⟩ lemma is_O.bound {f : α → E} {g : α → F} {l : filter α} : is_O f g l → ∃ c : ℝ, ∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥ := is_O_iff.1 /-- The Landau notation `is_o f g l` where `f` and `g` are two functions on a type `α` and `l` is a filter on `α`, means that eventually for `l`, `∥f∥` is bounded by an arbitrarily small constant multiple of `∥g∥`. In other words, `∥f∥ / ∥g∥` tends to `0` along `l`, modulo division by zero issues that are avoided by this definition. -/ @[irreducible] def is_o (f : α → E) (g : α → F) (l : filter α) : Prop := ∀ ⦃c : ℝ⦄, 0 < c → is_O_with c f g l /-- Definition of `is_o` in terms of `is_O_with`. We record it in a lemma as we will set `is_o` to be irreducible at the end of this file. -/ lemma is_o_iff_forall_is_O_with {f : α → E} {g : α → F} {l : filter α} : is_o f g l ↔ ∀ ⦃c : ℝ⦄, 0 < c → is_O_with c f g l := by rw is_o alias is_o_iff_forall_is_O_with ↔ asymptotics.is_o.forall_is_O_with asymptotics.is_o.of_is_O_with /-- Definition of `is_o` in terms of filters. We record it in a lemma as we will set `is_o` to be irreducible at the end of this file. -/ lemma is_o_iff {f : α → E} {g : α → F} {l : filter α} : is_o f g l ↔ ∀ ⦃c : ℝ⦄, 0 < c → ∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥ := by simp only [is_o, is_O_with] alias is_o_iff ↔ asymptotics.is_o.bound asymptotics.is_o.of_bound lemma is_o.def {f : α → E} {g : α → F} {l : filter α} (h : is_o f g l) {c : ℝ} (hc : 0 < c) : ∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥ := is_o_iff.1 h hc lemma is_o.def' {f : α → E} {g : α → F} {l : filter α} (h : is_o f g l) {c : ℝ} (hc : 0 < c) : is_O_with c f g l := is_O_with_iff.2 $ is_o_iff.1 h hc end defs /-! ### Conversions -/ theorem is_O_with.is_O (h : is_O_with c f g l) : is_O f g l := by rw is_O; exact ⟨c, h⟩ theorem is_o.is_O_with (hgf : is_o f g l) : is_O_with 1 f g l := hgf.def' zero_lt_one theorem is_o.is_O (hgf : is_o f g l) : is_O f g l := hgf.is_O_with.is_O lemma is_O.is_O_with {f : α → E} {g : α → F} {l : filter α} : is_O f g l → ∃ c : ℝ, is_O_with c f g l := is_O_iff_is_O_with.1 theorem is_O_with.weaken (h : is_O_with c f g' l) (hc : c ≤ c') : is_O_with c' f g' l := is_O_with.of_bound $ mem_of_superset h.bound $ λ x hx, calc ∥f x∥ ≤ c * ∥g' x∥ : hx ... ≤ _ : mul_le_mul_of_nonneg_right hc (norm_nonneg _) theorem is_O_with.exists_pos (h : is_O_with c f g' l) : ∃ c' (H : 0 < c'), is_O_with c' f g' l := ⟨max c 1, lt_of_lt_of_le zero_lt_one (le_max_right c 1), h.weaken $ le_max_left c 1⟩ theorem is_O.exists_pos (h : is_O f g' l) : ∃ c (H : 0 < c), is_O_with c f g' l := let ⟨c, hc⟩ := h.is_O_with in hc.exists_pos theorem is_O_with.exists_nonneg (h : is_O_with c f g' l) : ∃ c' (H : 0 ≤ c'), is_O_with c' f g' l := let ⟨c, cpos, hc⟩ := h.exists_pos in ⟨c, le_of_lt cpos, hc⟩ theorem is_O.exists_nonneg (h : is_O f g' l) : ∃ c (H : 0 ≤ c), is_O_with c f g' l := let ⟨c, hc⟩ := h.is_O_with in hc.exists_nonneg /-- `f = O(g)` if and only if `is_O_with c f g` for all sufficiently large `c`. -/ lemma is_O_iff_eventually_is_O_with : is_O f g' l ↔ ∀ᶠ c in at_top, is_O_with c f g' l := is_O_iff_is_O_with.trans ⟨λ ⟨c, hc⟩, mem_at_top_sets.2 ⟨c, λ c' hc', hc.weaken hc'⟩, λ h, h.exists⟩ /-- `f = O(g)` if and only if `∀ᶠ x in l, ∥f x∥ ≤ c * ∥g x∥` for all sufficiently large `c`. -/ lemma is_O_iff_eventually : is_O f g' l ↔ ∀ᶠ c in at_top, ∀ᶠ x in l, ∥f x∥ ≤ c * ∥g' x∥ := is_O_iff_eventually_is_O_with.trans $ by simp only [is_O_with] /-! ### Subsingleton -/ @[nontriviality] lemma is_o_of_subsingleton [subsingleton E'] : is_o f' g' l := is_o.of_bound $ λ c hc, by simp [subsingleton.elim (f' _) 0, mul_nonneg hc.le] @[nontriviality] lemma is_O_of_subsingleton [subsingleton E'] : is_O f' g' l := is_o_of_subsingleton.is_O /-! ### Congruence -/ theorem is_O_with_congr {c₁ c₂} {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α} (hc : c₁ = c₂) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : is_O_with c₁ f₁ g₁ l ↔ is_O_with c₂ f₂ g₂ l := begin unfold is_O_with, subst c₂, apply filter.eventually_congr, filter_upwards [hf, hg], assume x e₁ e₂, rw [e₁, e₂] end theorem is_O_with.congr' {c₁ c₂} {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α} (hc : c₁ = c₂) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : is_O_with c₁ f₁ g₁ l → is_O_with c₂ f₂ g₂ l := (is_O_with_congr hc hf hg).mp theorem is_O_with.congr {c₁ c₂} {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α} (hc : c₁ = c₂) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) : is_O_with c₁ f₁ g₁ l → is_O_with c₂ f₂ g₂ l := λ h, h.congr' hc (univ_mem' hf) (univ_mem' hg) theorem is_O_with.congr_left {f₁ f₂ : α → E} {l : filter α} (hf : ∀ x, f₁ x = f₂ x) : is_O_with c f₁ g l → is_O_with c f₂ g l := is_O_with.congr rfl hf (λ _, rfl) theorem is_O_with.congr_right {g₁ g₂ : α → F} {l : filter α} (hg : ∀ x, g₁ x = g₂ x) : is_O_with c f g₁ l → is_O_with c f g₂ l := is_O_with.congr rfl (λ _, rfl) hg theorem is_O_with.congr_const {c₁ c₂} {l : filter α} (hc : c₁ = c₂) : is_O_with c₁ f g l → is_O_with c₂ f g l := is_O_with.congr hc (λ _, rfl) (λ _, rfl) theorem is_O_congr {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α} (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : is_O f₁ g₁ l ↔ is_O f₂ g₂ l := by { unfold is_O, exact exists_congr (λ c, is_O_with_congr rfl hf hg) } theorem is_O.congr' {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α} (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : is_O f₁ g₁ l → is_O f₂ g₂ l := (is_O_congr hf hg).mp theorem is_O.congr {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α} (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) : is_O f₁ g₁ l → is_O f₂ g₂ l := λ h, h.congr' (univ_mem' hf) (univ_mem' hg) theorem is_O.congr_left {f₁ f₂ : α → E} {l : filter α} (hf : ∀ x, f₁ x = f₂ x) : is_O f₁ g l → is_O f₂ g l := is_O.congr hf (λ _, rfl) theorem is_O.congr_right {g₁ g₂ : α → E} {l : filter α} (hg : ∀ x, g₁ x = g₂ x) : is_O f g₁ l → is_O f g₂ l := is_O.congr (λ _, rfl) hg theorem is_o_congr {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α} (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : is_o f₁ g₁ l ↔ is_o f₂ g₂ l := by { unfold is_o, exact ball_congr (λ c hc, is_O_with_congr (eq.refl c) hf hg) } theorem is_o.congr' {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α} (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : is_o f₁ g₁ l → is_o f₂ g₂ l := (is_o_congr hf hg).mp theorem is_o.congr {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α} (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) : is_o f₁ g₁ l → is_o f₂ g₂ l := λ h, h.congr' (univ_mem' hf) (univ_mem' hg) theorem is_o.congr_left {f₁ f₂ : α → E} {l : filter α} (hf : ∀ x, f₁ x = f₂ x) : is_o f₁ g l → is_o f₂ g l := is_o.congr hf (λ _, rfl) theorem is_o.congr_right {g₁ g₂ : α → E} {l : filter α} (hg : ∀ x, g₁ x = g₂ x) : is_o f g₁ l → is_o f g₂ l := is_o.congr (λ _, rfl) hg /-! ### Filter operations and transitivity -/ theorem is_O_with.comp_tendsto (hcfg : is_O_with c f g l) {k : β → α} {l' : filter β} (hk : tendsto k l' l): is_O_with c (f ∘ k) (g ∘ k) l' := is_O_with.of_bound $ hk hcfg.bound theorem is_O.comp_tendsto (hfg : is_O f g l) {k : β → α} {l' : filter β} (hk : tendsto k l' l) : is_O (f ∘ k) (g ∘ k) l' := is_O_iff_is_O_with.2 $ hfg.is_O_with.imp (λ c h, h.comp_tendsto hk) theorem is_o.comp_tendsto (hfg : is_o f g l) {k : β → α} {l' : filter β} (hk : tendsto k l' l) : is_o (f ∘ k) (g ∘ k) l' := is_o.of_is_O_with $ λ c cpos, (hfg.forall_is_O_with cpos).comp_tendsto hk @[simp] theorem is_O_with_map {k : β → α} {l : filter β} : is_O_with c f g (map k l) ↔ is_O_with c (f ∘ k) (g ∘ k) l := by { unfold is_O_with, exact mem_map } @[simp] theorem is_O_map {k : β → α} {l : filter β} : is_O f g (map k l) ↔ is_O (f ∘ k) (g ∘ k) l := by simp only [is_O, is_O_with_map] @[simp] theorem is_o_map {k : β → α} {l : filter β} : is_o f g (map k l) ↔ is_o (f ∘ k) (g ∘ k) l := by simp only [is_o, is_O_with_map] theorem is_O_with.mono (h : is_O_with c f g l') (hl : l ≤ l') : is_O_with c f g l := is_O_with.of_bound $ hl h.bound theorem is_O.mono (h : is_O f g l') (hl : l ≤ l') : is_O f g l := is_O_iff_is_O_with.2 $ h.is_O_with.imp (λ c h, h.mono hl) theorem is_o.mono (h : is_o f g l') (hl : l ≤ l') : is_o f g l := is_o.of_is_O_with $ λ c cpos, (h.forall_is_O_with cpos).mono hl theorem is_O_with.trans (hfg : is_O_with c f g l) (hgk : is_O_with c' g k l) (hc : 0 ≤ c) : is_O_with (c * c') f k l := begin unfold is_O_with at *, filter_upwards [hfg, hgk], assume x hx hx', calc ∥f x∥ ≤ c * ∥g x∥ : hx ... ≤ c * (c' * ∥k x∥) : mul_le_mul_of_nonneg_left hx' hc ... = c * c' * ∥k x∥ : (mul_assoc _ _ _).symm end theorem is_O.trans (hfg : is_O f g' l) (hgk : is_O g' k l) : is_O f k l := let ⟨c, cnonneg, hc⟩ := hfg.exists_nonneg, ⟨c', hc'⟩ := hgk.is_O_with in (hc.trans hc' cnonneg).is_O theorem is_o.trans_is_O_with (hfg : is_o f g l) (hgk : is_O_with c g k l) (hc : 0 < c) : is_o f k l := begin unfold is_o at *, intros c' c'pos, have : 0 < c' / c, from div_pos c'pos hc, exact ((hfg this).trans hgk (le_of_lt this)).congr_const (div_mul_cancel _ (ne_of_gt hc)) end theorem is_o.trans_is_O (hfg : is_o f g l) (hgk : is_O g k' l) : is_o f k' l := let ⟨c, cpos, hc⟩ := hgk.exists_pos in hfg.trans_is_O_with hc cpos theorem is_O_with.trans_is_o (hfg : is_O_with c f g l) (hgk : is_o g k l) (hc : 0 < c) : is_o f k l := begin unfold is_o at *, intros c' c'pos, have : 0 < c' / c, from div_pos c'pos hc, exact (hfg.trans (hgk this) (le_of_lt hc)).congr_const (mul_div_cancel' _ (ne_of_gt hc)) end theorem is_O.trans_is_o (hfg : is_O f g' l) (hgk : is_o g' k l) : is_o f k l := let ⟨c, cpos, hc⟩ := hfg.exists_pos in hc.trans_is_o hgk cpos theorem is_o.trans (hfg : is_o f g l) (hgk : is_o g k' l) : is_o f k' l := hfg.trans_is_O hgk.is_O theorem is_o.trans' (hfg : is_o f g' l) (hgk : is_o g' k l) : is_o f k l := hfg.is_O.trans_is_o hgk section variable (l) theorem is_O_with_of_le' (hfg : ∀ x, ∥f x∥ ≤ c * ∥g x∥) : is_O_with c f g l := is_O_with.of_bound $ univ_mem' hfg theorem is_O_with_of_le (hfg : ∀ x, ∥f x∥ ≤ ∥g x∥) : is_O_with 1 f g l := is_O_with_of_le' l $ λ x, by { rw one_mul, exact hfg x } theorem is_O_of_le' (hfg : ∀ x, ∥f x∥ ≤ c * ∥g x∥) : is_O f g l := (is_O_with_of_le' l hfg).is_O theorem is_O_of_le (hfg : ∀ x, ∥f x∥ ≤ ∥g x∥) : is_O f g l := (is_O_with_of_le l hfg).is_O end theorem is_O_with_refl (f : α → E) (l : filter α) : is_O_with 1 f f l := is_O_with_of_le l $ λ _, le_refl _ theorem is_O_refl (f : α → E) (l : filter α) : is_O f f l := (is_O_with_refl f l).is_O theorem is_O_with.trans_le (hfg : is_O_with c f g l) (hgk : ∀ x, ∥g x∥ ≤ ∥k x∥) (hc : 0 ≤ c) : is_O_with c f k l := (hfg.trans (is_O_with_of_le l hgk) hc).congr_const $ mul_one c theorem is_O.trans_le (hfg : is_O f g' l) (hgk : ∀ x, ∥g' x∥ ≤ ∥k x∥) : is_O f k l := hfg.trans (is_O_of_le l hgk) theorem is_o.trans_le (hfg : is_o f g l) (hgk : ∀ x, ∥g x∥ ≤ ∥k x∥) : is_o f k l := hfg.trans_is_O_with (is_O_with_of_le _ hgk) zero_lt_one section bot variables (c f g) @[simp] theorem is_O_with_bot : is_O_with c f g ⊥ := is_O_with.of_bound $ trivial @[simp] theorem is_O_bot : is_O f g ⊥ := (is_O_with_bot 1 f g).is_O @[simp] theorem is_o_bot : is_o f g ⊥ := is_o.of_is_O_with $ λ c _, is_O_with_bot c f g end bot theorem is_O_with.join (h : is_O_with c f g l) (h' : is_O_with c f g l') : is_O_with c f g (l ⊔ l') := is_O_with.of_bound $ mem_sup.2 ⟨h.bound, h'.bound⟩ theorem is_O_with.join' (h : is_O_with c f g' l) (h' : is_O_with c' f g' l') : is_O_with (max c c') f g' (l ⊔ l') := is_O_with.of_bound $ mem_sup.2 ⟨(h.weaken $ le_max_left c c').bound, (h'.weaken $ le_max_right c c').bound⟩ theorem is_O.join (h : is_O f g' l) (h' : is_O f g' l') : is_O f g' (l ⊔ l') := let ⟨c, hc⟩ := h.is_O_with, ⟨c', hc'⟩ := h'.is_O_with in (hc.join' hc').is_O theorem is_o.join (h : is_o f g l) (h' : is_o f g l') : is_o f g (l ⊔ l') := is_o.of_is_O_with $ λ c cpos, (h.forall_is_O_with cpos).join (h'.forall_is_O_with cpos) /-! ### Simplification : norm -/ @[simp] theorem is_O_with_norm_right : is_O_with c f (λ x, ∥g' x∥) l ↔ is_O_with c f g' l := by simp only [is_O_with, norm_norm] alias is_O_with_norm_right ↔ asymptotics.is_O_with.of_norm_right asymptotics.is_O_with.norm_right @[simp] theorem is_O_norm_right : is_O f (λ x, ∥g' x∥) l ↔ is_O f g' l := by { unfold is_O, exact exists_congr (λ _, is_O_with_norm_right) } alias is_O_norm_right ↔ asymptotics.is_O.of_norm_right asymptotics.is_O.norm_right @[simp] theorem is_o_norm_right : is_o f (λ x, ∥g' x∥) l ↔ is_o f g' l := by { unfold is_o, exact forall_congr (λ _, forall_congr $ λ _, is_O_with_norm_right) } alias is_o_norm_right ↔ asymptotics.is_o.of_norm_right asymptotics.is_o.norm_right @[simp] theorem is_O_with_norm_left : is_O_with c (λ x, ∥f' x∥) g l ↔ is_O_with c f' g l := by simp only [is_O_with, norm_norm] alias is_O_with_norm_left ↔ asymptotics.is_O_with.of_norm_left asymptotics.is_O_with.norm_left @[simp] theorem is_O_norm_left : is_O (λ x, ∥f' x∥) g l ↔ is_O f' g l := by { unfold is_O, exact exists_congr (λ _, is_O_with_norm_left) } alias is_O_norm_left ↔ asymptotics.is_O.of_norm_left asymptotics.is_O.norm_left @[simp] theorem is_o_norm_left : is_o (λ x, ∥f' x∥) g l ↔ is_o f' g l := by { unfold is_o, exact forall_congr (λ _, forall_congr $ λ _, is_O_with_norm_left) } alias is_o_norm_left ↔ asymptotics.is_o.of_norm_left asymptotics.is_o.norm_left theorem is_O_with_norm_norm : is_O_with c (λ x, ∥f' x∥) (λ x, ∥g' x∥) l ↔ is_O_with c f' g' l := is_O_with_norm_left.trans is_O_with_norm_right alias is_O_with_norm_norm ↔ asymptotics.is_O_with.of_norm_norm asymptotics.is_O_with.norm_norm theorem is_O_norm_norm : is_O (λ x, ∥f' x∥) (λ x, ∥g' x∥) l ↔ is_O f' g' l := is_O_norm_left.trans is_O_norm_right alias is_O_norm_norm ↔ asymptotics.is_O.of_norm_norm asymptotics.is_O.norm_norm theorem is_o_norm_norm : is_o (λ x, ∥f' x∥) (λ x, ∥g' x∥) l ↔ is_o f' g' l := is_o_norm_left.trans is_o_norm_right alias is_o_norm_norm ↔ asymptotics.is_o.of_norm_norm asymptotics.is_o.norm_norm /-! ### Simplification: negate -/ @[simp] theorem is_O_with_neg_right : is_O_with c f (λ x, -(g' x)) l ↔ is_O_with c f g' l := by simp only [is_O_with, norm_neg] alias is_O_with_neg_right ↔ asymptotics.is_O_with.of_neg_right asymptotics.is_O_with.neg_right @[simp] theorem is_O_neg_right : is_O f (λ x, -(g' x)) l ↔ is_O f g' l := by { unfold is_O, exact exists_congr (λ _, is_O_with_neg_right) } alias is_O_neg_right ↔ asymptotics.is_O.of_neg_right asymptotics.is_O.neg_right @[simp] theorem is_o_neg_right : is_o f (λ x, -(g' x)) l ↔ is_o f g' l := by { unfold is_o, exact forall_congr (λ _, (forall_congr (λ _, is_O_with_neg_right))) } alias is_o_neg_right ↔ asymptotics.is_o.of_neg_right asymptotics.is_o.neg_right @[simp] theorem is_O_with_neg_left : is_O_with c (λ x, -(f' x)) g l ↔ is_O_with c f' g l := by simp only [is_O_with, norm_neg] alias is_O_with_neg_left ↔ asymptotics.is_O_with.of_neg_left asymptotics.is_O_with.neg_left @[simp] theorem is_O_neg_left : is_O (λ x, -(f' x)) g l ↔ is_O f' g l := by { unfold is_O, exact exists_congr (λ _, is_O_with_neg_left) } alias is_O_neg_left ↔ asymptotics.is_O.of_neg_left asymptotics.is_O.neg_left @[simp] theorem is_o_neg_left : is_o (λ x, -(f' x)) g l ↔ is_o f' g l := by { unfold is_o, exact forall_congr (λ _, (forall_congr (λ _, is_O_with_neg_left))) } alias is_o_neg_left ↔ asymptotics.is_o.of_neg_right asymptotics.is_o.neg_left /-! ### Product of functions (right) -/ lemma is_O_with_fst_prod : is_O_with 1 f' (λ x, (f' x, g' x)) l := is_O_with_of_le l $ λ x, le_max_left _ _ lemma is_O_with_snd_prod : is_O_with 1 g' (λ x, (f' x, g' x)) l := is_O_with_of_le l $ λ x, le_max_right _ _ lemma is_O_fst_prod : is_O f' (λ x, (f' x, g' x)) l := is_O_with_fst_prod.is_O lemma is_O_snd_prod : is_O g' (λ x, (f' x, g' x)) l := is_O_with_snd_prod.is_O lemma is_O_fst_prod' {f' : α → E' × F'} : is_O (λ x, (f' x).1) f' l := by simpa [is_O, is_O_with] using is_O_fst_prod lemma is_O_snd_prod' {f' : α → E' × F'} : is_O (λ x, (f' x).2) f' l := by simpa [is_O, is_O_with] using is_O_snd_prod section variables (f' k') lemma is_O_with.prod_rightl (h : is_O_with c f g' l) (hc : 0 ≤ c) : is_O_with c f (λ x, (g' x, k' x)) l := (h.trans is_O_with_fst_prod hc).congr_const (mul_one c) lemma is_O.prod_rightl (h : is_O f g' l) : is_O f (λx, (g' x, k' x)) l := let ⟨c, cnonneg, hc⟩ := h.exists_nonneg in (hc.prod_rightl k' cnonneg).is_O lemma is_o.prod_rightl (h : is_o f g' l) : is_o f (λ x, (g' x, k' x)) l := is_o.of_is_O_with $ λ c cpos, (h.forall_is_O_with cpos).prod_rightl k' (le_of_lt cpos) lemma is_O_with.prod_rightr (h : is_O_with c f g' l) (hc : 0 ≤ c) : is_O_with c f (λ x, (f' x, g' x)) l := (h.trans is_O_with_snd_prod hc).congr_const (mul_one c) lemma is_O.prod_rightr (h : is_O f g' l) : is_O f (λx, (f' x, g' x)) l := let ⟨c, cnonneg, hc⟩ := h.exists_nonneg in (hc.prod_rightr f' cnonneg).is_O lemma is_o.prod_rightr (h : is_o f g' l) : is_o f (λx, (f' x, g' x)) l := is_o.of_is_O_with $ λ c cpos, (h.forall_is_O_with cpos).prod_rightr f' (le_of_lt cpos) end lemma is_O_with.prod_left_same (hf : is_O_with c f' k' l) (hg : is_O_with c g' k' l) : is_O_with c (λ x, (f' x, g' x)) k' l := by rw is_O_with_iff at *; filter_upwards [hf, hg] λ x, max_le lemma is_O_with.prod_left (hf : is_O_with c f' k' l) (hg : is_O_with c' g' k' l) : is_O_with (max c c') (λ x, (f' x, g' x)) k' l := (hf.weaken $ le_max_left c c').prod_left_same (hg.weaken $ le_max_right c c') lemma is_O_with.prod_left_fst (h : is_O_with c (λ x, (f' x, g' x)) k' l) : is_O_with c f' k' l := (is_O_with_fst_prod.trans h zero_le_one).congr_const $ one_mul c lemma is_O_with.prod_left_snd (h : is_O_with c (λ x, (f' x, g' x)) k' l) : is_O_with c g' k' l := (is_O_with_snd_prod.trans h zero_le_one).congr_const $ one_mul c lemma is_O_with_prod_left : is_O_with c (λ x, (f' x, g' x)) k' l ↔ is_O_with c f' k' l ∧ is_O_with c g' k' l := ⟨λ h, ⟨h.prod_left_fst, h.prod_left_snd⟩, λ h, h.1.prod_left_same h.2⟩ lemma is_O.prod_left (hf : is_O f' k' l) (hg : is_O g' k' l) : is_O (λ x, (f' x, g' x)) k' l := let ⟨c, hf⟩ := hf.is_O_with, ⟨c', hg⟩ := hg.is_O_with in (hf.prod_left hg).is_O lemma is_O.prod_left_fst (h : is_O (λ x, (f' x, g' x)) k' l) : is_O f' k' l := is_O_fst_prod.trans h lemma is_O.prod_left_snd (h : is_O (λ x, (f' x, g' x)) k' l) : is_O g' k' l := is_O_snd_prod.trans h @[simp] lemma is_O_prod_left : is_O (λ x, (f' x, g' x)) k' l ↔ is_O f' k' l ∧ is_O g' k' l := ⟨λ h, ⟨h.prod_left_fst, h.prod_left_snd⟩, λ h, h.1.prod_left h.2⟩ lemma is_o.prod_left (hf : is_o f' k' l) (hg : is_o g' k' l) : is_o (λ x, (f' x, g' x)) k' l := is_o.of_is_O_with $ λ c hc, (hf.forall_is_O_with hc).prod_left_same (hg.forall_is_O_with hc) lemma is_o.prod_left_fst (h : is_o (λ x, (f' x, g' x)) k' l) : is_o f' k' l := is_O_fst_prod.trans_is_o h lemma is_o.prod_left_snd (h : is_o (λ x, (f' x, g' x)) k' l) : is_o g' k' l := is_O_snd_prod.trans_is_o h @[simp] lemma is_o_prod_left : is_o (λ x, (f' x, g' x)) k' l ↔ is_o f' k' l ∧ is_o g' k' l := ⟨λ h, ⟨h.prod_left_fst, h.prod_left_snd⟩, λ h, h.1.prod_left h.2⟩ lemma is_O_with.eq_zero_imp (h : is_O_with c f' g' l) : ∀ᶠ x in l, g' x = 0 → f' x = 0 := eventually.mono h.bound $ λ x hx hg, norm_le_zero_iff.1 $ by simpa [hg] using hx lemma is_O.eq_zero_imp (h : is_O f' g' l) : ∀ᶠ x in l, g' x = 0 → f' x = 0 := let ⟨C, hC⟩ := h.is_O_with in hC.eq_zero_imp /-! ### Addition and subtraction -/ section add_sub variables {c₁ c₂ : ℝ} {f₁ f₂ : α → E'} theorem is_O_with.add (h₁ : is_O_with c₁ f₁ g l) (h₂ : is_O_with c₂ f₂ g l) : is_O_with (c₁ + c₂) (λ x, f₁ x + f₂ x) g l := by rw is_O_with at *; filter_upwards [h₁, h₂] λ x hx₁ hx₂, calc ∥f₁ x + f₂ x∥ ≤ c₁ * ∥g x∥ + c₂ * ∥g x∥ : norm_add_le_of_le hx₁ hx₂ ... = (c₁ + c₂) * ∥g x∥ : (add_mul _ _ _).symm theorem is_O.add (h₁ : is_O f₁ g l) (h₂ : is_O f₂ g l) : is_O (λ x, f₁ x + f₂ x) g l := let ⟨c₁, hc₁⟩ := h₁.is_O_with, ⟨c₂, hc₂⟩ := h₂.is_O_with in (hc₁.add hc₂).is_O theorem is_o.add (h₁ : is_o f₁ g l) (h₂ : is_o f₂ g l) : is_o (λ x, f₁ x + f₂ x) g l := is_o.of_is_O_with $ λ c cpos, ((h₁.forall_is_O_with $ half_pos cpos).add (h₂.forall_is_O_with $ half_pos cpos)).congr_const (add_halves c) theorem is_o.add_add {g₁ g₂ : α → F'} (h₁ : is_o f₁ g₁ l) (h₂ : is_o f₂ g₂ l) : is_o (λ x, f₁ x + f₂ x) (λ x, ∥g₁ x∥ + ∥g₂ x∥) l := by refine (h₁.trans_le $ λ x, _).add (h₂.trans_le _); simp [real.norm_eq_abs, abs_of_nonneg, add_nonneg] theorem is_O.add_is_o (h₁ : is_O f₁ g l) (h₂ : is_o f₂ g l) : is_O (λ x, f₁ x + f₂ x) g l := h₁.add h₂.is_O theorem is_o.add_is_O (h₁ : is_o f₁ g l) (h₂ : is_O f₂ g l) : is_O (λ x, f₁ x + f₂ x) g l := h₁.is_O.add h₂ theorem is_O_with.add_is_o (h₁ : is_O_with c₁ f₁ g l) (h₂ : is_o f₂ g l) (hc : c₁ < c₂) : is_O_with c₂ (λx, f₁ x + f₂ x) g l := (h₁.add (h₂.forall_is_O_with (sub_pos.2 hc))).congr_const (add_sub_cancel'_right _ _) theorem is_o.add_is_O_with (h₁ : is_o f₁ g l) (h₂ : is_O_with c₁ f₂ g l) (hc : c₁ < c₂) : is_O_with c₂ (λx, f₁ x + f₂ x) g l := (h₂.add_is_o h₁ hc).congr_left $ λ _, add_comm _ _ theorem is_O_with.sub (h₁ : is_O_with c₁ f₁ g l) (h₂ : is_O_with c₂ f₂ g l) : is_O_with (c₁ + c₂) (λ x, f₁ x - f₂ x) g l := by simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left theorem is_O_with.sub_is_o (h₁ : is_O_with c₁ f₁ g l) (h₂ : is_o f₂ g l) (hc : c₁ < c₂) : is_O_with c₂ (λ x, f₁ x - f₂ x) g l := by simpa only [sub_eq_add_neg] using h₁.add_is_o h₂.neg_left hc theorem is_O.sub (h₁ : is_O f₁ g l) (h₂ : is_O f₂ g l) : is_O (λ x, f₁ x - f₂ x) g l := by simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left theorem is_o.sub (h₁ : is_o f₁ g l) (h₂ : is_o f₂ g l) : is_o (λ x, f₁ x - f₂ x) g l := by simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left end add_sub /-! ### Lemmas about `is_O (f₁ - f₂) g l` / `is_o (f₁ - f₂) g l` treated as a binary relation -/ section is_oO_as_rel variables {f₁ f₂ f₃ : α → E'} theorem is_O_with.symm (h : is_O_with c (λ x, f₁ x - f₂ x) g l) : is_O_with c (λ x, f₂ x - f₁ x) g l := h.neg_left.congr_left $ λ x, neg_sub _ _ theorem is_O_with_comm : is_O_with c (λ x, f₁ x - f₂ x) g l ↔ is_O_with c (λ x, f₂ x - f₁ x) g l := ⟨is_O_with.symm, is_O_with.symm⟩ theorem is_O.symm (h : is_O (λ x, f₁ x - f₂ x) g l) : is_O (λ x, f₂ x - f₁ x) g l := h.neg_left.congr_left $ λ x, neg_sub _ _ theorem is_O_comm : is_O (λ x, f₁ x - f₂ x) g l ↔ is_O (λ x, f₂ x - f₁ x) g l := ⟨is_O.symm, is_O.symm⟩ theorem is_o.symm (h : is_o (λ x, f₁ x - f₂ x) g l) : is_o (λ x, f₂ x - f₁ x) g l := by simpa only [neg_sub] using h.neg_left theorem is_o_comm : is_o (λ x, f₁ x - f₂ x) g l ↔ is_o (λ x, f₂ x - f₁ x) g l := ⟨is_o.symm, is_o.symm⟩ theorem is_O_with.triangle (h₁ : is_O_with c (λ x, f₁ x - f₂ x) g l) (h₂ : is_O_with c' (λ x, f₂ x - f₃ x) g l) : is_O_with (c + c') (λ x, f₁ x - f₃ x) g l := (h₁.add h₂).congr_left $ λ x, sub_add_sub_cancel _ _ _ theorem is_O.triangle (h₁ : is_O (λ x, f₁ x - f₂ x) g l) (h₂ : is_O (λ x, f₂ x - f₃ x) g l) : is_O (λ x, f₁ x - f₃ x) g l := (h₁.add h₂).congr_left $ λ x, sub_add_sub_cancel _ _ _ theorem is_o.triangle (h₁ : is_o (λ x, f₁ x - f₂ x) g l) (h₂ : is_o (λ x, f₂ x - f₃ x) g l) : is_o (λ x, f₁ x - f₃ x) g l := (h₁.add h₂).congr_left $ λ x, sub_add_sub_cancel _ _ _ theorem is_O.congr_of_sub (h : is_O (λ x, f₁ x - f₂ x) g l) : is_O f₁ g l ↔ is_O f₂ g l := ⟨λ h', (h'.sub h).congr_left (λ x, sub_sub_cancel _ _), λ h', (h.add h').congr_left (λ x, sub_add_cancel _ _)⟩ theorem is_o.congr_of_sub (h : is_o (λ x, f₁ x - f₂ x) g l) : is_o f₁ g l ↔ is_o f₂ g l := ⟨λ h', (h'.sub h).congr_left (λ x, sub_sub_cancel _ _), λ h', (h.add h').congr_left (λ x, sub_add_cancel _ _)⟩ end is_oO_as_rel /-! ### Zero, one, and other constants -/ section zero_const variables (g g' l) theorem is_o_zero : is_o (λ x, (0 : E')) g' l := is_o.of_bound $ λ c hc, univ_mem' $ λ x, by simpa using mul_nonneg (le_of_lt hc) (norm_nonneg $ g' x) theorem is_O_with_zero (hc : 0 ≤ c) : is_O_with c (λ x, (0 : E')) g' l := is_O_with.of_bound $ univ_mem' $ λ x, by simpa using mul_nonneg hc (norm_nonneg $ g' x) theorem is_O_with_zero' : is_O_with 0 (λ x, (0 : E')) g l := is_O_with.of_bound $ univ_mem' $ λ x, by simp theorem is_O_zero : is_O (λ x, (0 : E')) g l := is_O_iff_is_O_with.2 ⟨0, is_O_with_zero' _ _⟩ theorem is_O_refl_left : is_O (λ x, f' x - f' x) g' l := (is_O_zero g' l).congr_left $ λ x, (sub_self _).symm theorem is_o_refl_left : is_o (λ x, f' x - f' x) g' l := (is_o_zero g' l).congr_left $ λ x, (sub_self _).symm variables {g g' l} @[simp] theorem is_O_with_zero_right_iff : is_O_with c f' (λ x, (0 : F')) l ↔ ∀ᶠ x in l, f' x = 0 := by simp only [is_O_with, exists_prop, true_and, norm_zero, mul_zero, norm_le_zero_iff] @[simp] theorem is_O_zero_right_iff : is_O f' (λ x, (0 : F')) l ↔ ∀ᶠ x in l, f' x = 0 := ⟨λ h, let ⟨c, hc⟩ := h.is_O_with in is_O_with_zero_right_iff.1 hc, λ h, (is_O_with_zero_right_iff.2 h : is_O_with 1 _ _ _).is_O⟩ @[simp] theorem is_o_zero_right_iff : is_o f' (λ x, (0 : F')) l ↔ ∀ᶠ x in l, f' x = 0 := ⟨λ h, is_O_zero_right_iff.1 h.is_O, λ h, is_o.of_is_O_with $ λ c hc, is_O_with_zero_right_iff.2 h⟩ theorem is_O_with_const_const (c : E) {c' : F'} (hc' : c' ≠ 0) (l : filter α) : is_O_with (∥c∥ / ∥c'∥) (λ x : α, c) (λ x, c') l := begin unfold is_O_with, apply univ_mem', intro x, rw [mem_set_of_eq, div_mul_cancel], rwa [ne.def, norm_eq_zero] end theorem is_O_const_const (c : E) {c' : F'} (hc' : c' ≠ 0) (l : filter α) : is_O (λ x : α, c) (λ x, c') l := (is_O_with_const_const c hc' l).is_O end zero_const @[simp] lemma is_O_with_top : is_O_with c f g ⊤ ↔ ∀ x, ∥f x∥ ≤ c * ∥g x∥ := by rw is_O_with; refl @[simp] lemma is_O_top : is_O f g ⊤ ↔ ∃ C, ∀ x, ∥f x∥ ≤ C * ∥g x∥ := by rw is_O_iff; refl @[simp] lemma is_o_top : is_o f' g' ⊤ ↔ ∀ x, f' x = 0 := begin refine ⟨_, λ h, (is_o_zero g' ⊤).congr (λ x, (h x).symm) (λ x, rfl)⟩, simp only [is_o_iff, eventually_top], refine λ h x, norm_le_zero_iff.1 _, have : tendsto (λ c : ℝ, c * ∥g' x∥) (𝓝[Ioi 0] 0) (𝓝 0) := ((continuous_id.mul continuous_const).tendsto' _ _ (zero_mul _)).mono_left inf_le_left, exact le_of_tendsto_of_tendsto tendsto_const_nhds this (eventually_nhds_within_iff.2 $ eventually_of_forall $ λ c hc, h hc x) end @[simp] lemma is_O_with_principal {s : set α} : is_O_with c f g (𝓟 s) ↔ ∀ x ∈ s, ∥f x∥ ≤ c * ∥g x∥ := by rw is_O_with; refl lemma is_O_principal {s : set α} : is_O f g (𝓟 s) ↔ ∃ c, ∀ x ∈ s, ∥f x∥ ≤ c * ∥g x∥ := by rw is_O_iff; refl theorem is_O_with_const_one (c : E) (l : filter α) : is_O_with ∥c∥ (λ x : α, c) (λ x, (1 : 𝕜)) l := begin refine (is_O_with_const_const c _ l).congr_const _, { rw [norm_one, div_one] }, { exact one_ne_zero } end theorem is_O_const_one (c : E) (l : filter α) : is_O (λ x : α, c) (λ x, (1 : 𝕜)) l := (is_O_with_const_one c l).is_O section variable (𝕜) theorem is_o_const_iff_is_o_one {c : F'} (hc : c ≠ 0) : is_o f (λ x, c) l ↔ is_o f (λ x, (1:𝕜)) l := ⟨λ h, h.trans_is_O $ is_O_const_one c l, λ h, h.trans_is_O $ is_O_const_const _ hc _⟩ end theorem is_o_const_iff {c : F'} (hc : c ≠ 0) : is_o f' (λ x, c) l ↔ tendsto f' l (𝓝 0) := (is_o_const_iff_is_o_one ℝ hc).trans begin clear hc c, simp only [is_o, is_O_with, norm_one, mul_one, metric.nhds_basis_closed_ball.tendsto_right_iff, metric.mem_closed_ball, dist_zero_right] end theorem is_o_const_const_iff [ne_bot l] {d : E'} {c : F'} (hc : c ≠ 0) : is_o (λ x, d) (λ x, c) l ↔ d = 0 := begin rw is_o_const_iff hc, refine ⟨λ h, tendsto_nhds_unique tendsto_const_nhds h, _⟩, rintros rfl, exact tendsto_const_nhds, end lemma is_o_id_const {c : F'} (hc : c ≠ 0) : is_o (λ (x : E'), x) (λ x, c) (𝓝 0) := (is_o_const_iff hc).mpr (continuous_id.tendsto 0) theorem is_O_const_of_tendsto {y : E'} (h : tendsto f' l (𝓝 y)) {c : F'} (hc : c ≠ 0) : is_O f' (λ x, c) l := begin refine is_O.trans _ (is_O_const_const (∥y∥ + 1) hc l), refine is_O.of_bound 1 _, simp only [is_O_with, one_mul], have : tendsto (λx, ∥f' x∥) l (𝓝 ∥y∥), from (continuous_norm.tendsto _).comp h, have Iy : ∥y∥ < ∥∥y∥ + 1∥, from lt_of_lt_of_le (lt_add_one _) (le_abs_self _), exact this (ge_mem_nhds Iy) end section variable (𝕜) theorem is_o_one_iff : is_o f' (λ x, (1 : 𝕜)) l ↔ tendsto f' l (𝓝 0) := is_o_const_iff one_ne_zero theorem is_O_one_of_tendsto {y : E'} (h : tendsto f' l (𝓝 y)) : is_O f' (λ x, (1:𝕜)) l := is_O_const_of_tendsto h one_ne_zero theorem is_O.trans_tendsto_nhds (hfg : is_O f g' l) {y : F'} (hg : tendsto g' l (𝓝 y)) : is_O f (λ x, (1:𝕜)) l := hfg.trans $ is_O_one_of_tendsto 𝕜 hg end theorem is_O.trans_tendsto (hfg : is_O f' g' l) (hg : tendsto g' l (𝓝 0)) : tendsto f' l (𝓝 0) := (is_o_one_iff ℝ).1 $ hfg.trans_is_o $ (is_o_one_iff ℝ).2 hg theorem is_o.trans_tendsto (hfg : is_o f' g' l) (hg : tendsto g' l (𝓝 0)) : tendsto f' l (𝓝 0) := hfg.is_O.trans_tendsto hg /-! ### Multiplication by a constant -/ theorem is_O_with_const_mul_self (c : R) (f : α → R) (l : filter α) : is_O_with ∥c∥ (λ x, c * f x) f l := is_O_with_of_le' _ $ λ x, norm_mul_le _ _ theorem is_O_const_mul_self (c : R) (f : α → R) (l : filter α) : is_O (λ x, c * f x) f l := (is_O_with_const_mul_self c f l).is_O theorem is_O_with.const_mul_left {f : α → R} (h : is_O_with c f g l) (c' : R) : is_O_with (∥c'∥ * c) (λ x, c' * f x) g l := (is_O_with_const_mul_self c' f l).trans h (norm_nonneg c') theorem is_O.const_mul_left {f : α → R} (h : is_O f g l) (c' : R) : is_O (λ x, c' * f x) g l := let ⟨c, hc⟩ := h.is_O_with in (hc.const_mul_left c').is_O theorem is_O_with_self_const_mul' (u : units R) (f : α → R) (l : filter α) : is_O_with ∥(↑u⁻¹:R)∥ f (λ x, ↑u * f x) l := (is_O_with_const_mul_self ↑u⁻¹ _ l).congr_left $ λ x, u.inv_mul_cancel_left (f x) theorem is_O_with_self_const_mul (c : 𝕜) (hc : c ≠ 0) (f : α → 𝕜) (l : filter α) : is_O_with ∥c∥⁻¹ f (λ x, c * f x) l := (is_O_with_self_const_mul' (units.mk0 c hc) f l).congr_const $ normed_field.norm_inv c theorem is_O_self_const_mul' {c : R} (hc : is_unit c) (f : α → R) (l : filter α) : is_O f (λ x, c * f x) l := let ⟨u, hu⟩ := hc in hu ▸ (is_O_with_self_const_mul' u f l).is_O theorem is_O_self_const_mul (c : 𝕜) (hc : c ≠ 0) (f : α → 𝕜) (l : filter α) : is_O f (λ x, c * f x) l := is_O_self_const_mul' (is_unit.mk0 c hc) f l theorem is_O_const_mul_left_iff' {f : α → R} {c : R} (hc : is_unit c) : is_O (λ x, c * f x) g l ↔ is_O f g l := ⟨(is_O_self_const_mul' hc f l).trans, λ h, h.const_mul_left c⟩ theorem is_O_const_mul_left_iff {f : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : is_O (λ x, c * f x) g l ↔ is_O f g l := is_O_const_mul_left_iff' $ is_unit.mk0 c hc theorem is_o.const_mul_left {f : α → R} (h : is_o f g l) (c : R) : is_o (λ x, c * f x) g l := (is_O_const_mul_self c f l).trans_is_o h theorem is_o_const_mul_left_iff' {f : α → R} {c : R} (hc : is_unit c) : is_o (λ x, c * f x) g l ↔ is_o f g l := ⟨(is_O_self_const_mul' hc f l).trans_is_o, λ h, h.const_mul_left c⟩ theorem is_o_const_mul_left_iff {f : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : is_o (λ x, c * f x) g l ↔ is_o f g l := is_o_const_mul_left_iff' $ is_unit.mk0 c hc theorem is_O_with.of_const_mul_right {g : α → R} {c : R} (hc' : 0 ≤ c') (h : is_O_with c' f (λ x, c * g x) l) : is_O_with (c' * ∥c∥) f g l := h.trans (is_O_with_const_mul_self c g l) hc' theorem is_O.of_const_mul_right {g : α → R} {c : R} (h : is_O f (λ x, c * g x) l) : is_O f g l := let ⟨c, cnonneg, hc⟩ := h.exists_nonneg in (hc.of_const_mul_right cnonneg).is_O theorem is_O_with.const_mul_right' {g : α → R} {u : units R} {c' : ℝ} (hc' : 0 ≤ c') (h : is_O_with c' f g l) : is_O_with (c' * ∥(↑u⁻¹:R)∥) f (λ x, ↑u * g x) l := h.trans (is_O_with_self_const_mul' _ _ _) hc' theorem is_O_with.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) {c' : ℝ} (hc' : 0 ≤ c') (h : is_O_with c' f g l) : is_O_with (c' * ∥c∥⁻¹) f (λ x, c * g x) l := h.trans (is_O_with_self_const_mul c hc g l) hc' theorem is_O.const_mul_right' {g : α → R} {c : R} (hc : is_unit c) (h : is_O f g l) : is_O f (λ x, c * g x) l := h.trans (is_O_self_const_mul' hc g l) theorem is_O.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) (h : is_O f g l) : is_O f (λ x, c * g x) l := h.const_mul_right' $ is_unit.mk0 c hc theorem is_O_const_mul_right_iff' {g : α → R} {c : R} (hc : is_unit c) : is_O f (λ x, c * g x) l ↔ is_O f g l := ⟨λ h, h.of_const_mul_right, λ h, h.const_mul_right' hc⟩ theorem is_O_const_mul_right_iff {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : is_O f (λ x, c * g x) l ↔ is_O f g l := is_O_const_mul_right_iff' $ is_unit.mk0 c hc theorem is_o.of_const_mul_right {g : α → R} {c : R} (h : is_o f (λ x, c * g x) l) : is_o f g l := h.trans_is_O (is_O_const_mul_self c g l) theorem is_o.const_mul_right' {g : α → R} {c : R} (hc : is_unit c) (h : is_o f g l) : is_o f (λ x, c * g x) l := h.trans_is_O (is_O_self_const_mul' hc g l) theorem is_o.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) (h : is_o f g l) : is_o f (λ x, c * g x) l := h.const_mul_right' $ is_unit.mk0 c hc theorem is_o_const_mul_right_iff' {g : α → R} {c : R} (hc : is_unit c) : is_o f (λ x, c * g x) l ↔ is_o f g l := ⟨λ h, h.of_const_mul_right, λ h, h.const_mul_right' hc⟩ theorem is_o_const_mul_right_iff {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : is_o f (λ x, c * g x) l ↔ is_o f g l := is_o_const_mul_right_iff' $ is_unit.mk0 c hc /-! ### Multiplication -/ theorem is_O_with.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} {c₁ c₂ : ℝ} (h₁ : is_O_with c₁ f₁ g₁ l) (h₂ : is_O_with c₂ f₂ g₂ l) : is_O_with (c₁ * c₂) (λ x, f₁ x * f₂ x) (λ x, g₁ x * g₂ x) l := begin unfold is_O_with at *, filter_upwards [h₁, h₂], intros x hx₁ hx₂, apply le_trans (norm_mul_le _ _), convert mul_le_mul hx₁ hx₂ (norm_nonneg _) (le_trans (norm_nonneg _) hx₁) using 1, rw normed_field.norm_mul, ac_refl end theorem is_O.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : is_O f₁ g₁ l) (h₂ : is_O f₂ g₂ l) : is_O (λ x, f₁ x * f₂ x) (λ x, g₁ x * g₂ x) l := let ⟨c, hc⟩ := h₁.is_O_with, ⟨c', hc'⟩ := h₂.is_O_with in (hc.mul hc').is_O theorem is_O.mul_is_o {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : is_O f₁ g₁ l) (h₂ : is_o f₂ g₂ l) : is_o (λ x, f₁ x * f₂ x) (λ x, g₁ x * g₂ x) l := begin unfold is_o at *, intros c cpos, rcases h₁.exists_pos with ⟨c', c'pos, hc'⟩, exact (hc'.mul (h₂ (div_pos cpos c'pos))).congr_const (mul_div_cancel' _ (ne_of_gt c'pos)) end theorem is_o.mul_is_O {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : is_o f₁ g₁ l) (h₂ : is_O f₂ g₂ l) : is_o (λ x, f₁ x * f₂ x) (λ x, g₁ x * g₂ x) l := begin unfold is_o at *, intros c cpos, rcases h₂.exists_pos with ⟨c', c'pos, hc'⟩, exact ((h₁ (div_pos cpos c'pos)).mul hc').congr_const (div_mul_cancel _ (ne_of_gt c'pos)) end theorem is_o.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : is_o f₁ g₁ l) (h₂ : is_o f₂ g₂ l) : is_o (λ x, f₁ x * f₂ x) (λ x, g₁ x * g₂ x) l := h₁.mul_is_O h₂.is_O theorem is_O_with.pow' {f : α → R} {g : α → 𝕜} (h : is_O_with c f g l) : ∀ n : ℕ, is_O_with (nat.cases_on n ∥(1 : R)∥ (λ n, c ^ (n + 1))) (λ x, f x ^ n) (λ x, g x ^ n) l | 0 := by simpa using is_O_with_const_const (1 : R) (@one_ne_zero 𝕜 _ _) l | 1 := by simpa | (n + 2) := by simpa [pow_succ] using h.mul (is_O_with.pow' (n + 1)) theorem is_O_with.pow [norm_one_class R] {f : α → R} {g : α → 𝕜} (h : is_O_with c f g l) : ∀ n : ℕ, is_O_with (c ^ n) (λ x, f x ^ n) (λ x, g x ^ n) l | 0 := by simpa using h.pow' 0 | (n + 1) := h.pow' (n + 1) theorem is_O.pow {f : α → R} {g : α → 𝕜} (h : is_O f g l) (n : ℕ) : is_O (λ x, f x ^ n) (λ x, g x ^ n) l := let ⟨C, hC⟩ := h.is_O_with in is_O_iff_is_O_with.2 ⟨_, hC.pow' n⟩ theorem is_o.pow {f : α → R} {g : α → 𝕜} (h : is_o f g l) {n : ℕ} (hn : 0 < n) : is_o (λ x, f x ^ n) (λ x, g x ^ n) l := begin cases n, exact hn.false.elim, clear hn, induction n with n ihn, { simpa only [pow_one] }, convert h.mul ihn; simp [pow_succ] end /-! ### Scalar multiplication -/ section smul_const variables [normed_space 𝕜 E'] theorem is_O_with.const_smul_left (h : is_O_with c f' g l) (c' : 𝕜) : is_O_with (∥c'∥ * c) (λ x, c' • f' x) g l := by refine ((h.norm_left.const_mul_left (∥c'∥)).congr _ _ (λ _, rfl)).of_norm_left; intros; simp only [norm_norm, norm_smul] theorem is_O_const_smul_left_iff {c : 𝕜} (hc : c ≠ 0) : is_O (λ x, c • f' x) g l ↔ is_O f' g l := begin have cne0 : ∥c∥ ≠ 0, from mt norm_eq_zero.mp hc, rw [←is_O_norm_left], simp only [norm_smul], rw [is_O_const_mul_left_iff cne0, is_O_norm_left], end theorem is_o_const_smul_left (h : is_o f' g l) (c : 𝕜) : is_o (λ x, c • f' x) g l := begin refine ((h.norm_left.const_mul_left (∥c∥)).congr_left _).of_norm_left, exact λ x, (norm_smul _ _).symm end theorem is_o_const_smul_left_iff {c : 𝕜} (hc : c ≠ 0) : is_o (λ x, c • f' x) g l ↔ is_o f' g l := begin have cne0 : ∥c∥ ≠ 0, from mt norm_eq_zero.mp hc, rw [←is_o_norm_left], simp only [norm_smul], rw [is_o_const_mul_left_iff cne0, is_o_norm_left] end theorem is_O_const_smul_right {c : 𝕜} (hc : c ≠ 0) : is_O f (λ x, c • f' x) l ↔ is_O f f' l := begin have cne0 : ∥c∥ ≠ 0, from mt norm_eq_zero.mp hc, rw [←is_O_norm_right], simp only [norm_smul], rw [is_O_const_mul_right_iff cne0, is_O_norm_right] end theorem is_o_const_smul_right {c : 𝕜} (hc : c ≠ 0) : is_o f (λ x, c • f' x) l ↔ is_o f f' l := begin have cne0 : ∥c∥ ≠ 0, from mt norm_eq_zero.mp hc, rw [←is_o_norm_right], simp only [norm_smul], rw [is_o_const_mul_right_iff cne0, is_o_norm_right] end end smul_const section smul variables [normed_space 𝕜 E'] [normed_space 𝕜 F'] theorem is_O_with.smul {k₁ k₂ : α → 𝕜} (h₁ : is_O_with c k₁ k₂ l) (h₂ : is_O_with c' f' g' l) : is_O_with (c * c') (λ x, k₁ x • f' x) (λ x, k₂ x • g' x) l := by refine ((h₁.norm_norm.mul h₂.norm_norm).congr rfl _ _).of_norm_norm; by intros; simp only [norm_smul] theorem is_O.smul {k₁ k₂ : α → 𝕜} (h₁ : is_O k₁ k₂ l) (h₂ : is_O f' g' l) : is_O (λ x, k₁ x • f' x) (λ x, k₂ x • g' x) l := by refine ((h₁.norm_norm.mul h₂.norm_norm).congr _ _).of_norm_norm; by intros; simp only [norm_smul] theorem is_O.smul_is_o {k₁ k₂ : α → 𝕜} (h₁ : is_O k₁ k₂ l) (h₂ : is_o f' g' l) : is_o (λ x, k₁ x • f' x) (λ x, k₂ x • g' x) l := by refine ((h₁.norm_norm.mul_is_o h₂.norm_norm).congr _ _).of_norm_norm; by intros; simp only [norm_smul] theorem is_o.smul_is_O {k₁ k₂ : α → 𝕜} (h₁ : is_o k₁ k₂ l) (h₂ : is_O f' g' l) : is_o (λ x, k₁ x • f' x) (λ x, k₂ x • g' x) l := by refine ((h₁.norm_norm.mul_is_O h₂.norm_norm).congr _ _).of_norm_norm; by intros; simp only [norm_smul] theorem is_o.smul {k₁ k₂ : α → 𝕜} (h₁ : is_o k₁ k₂ l) (h₂ : is_o f' g' l) : is_o (λ x, k₁ x • f' x) (λ x, k₂ x • g' x) l := by refine ((h₁.norm_norm.mul h₂.norm_norm).congr _ _).of_norm_norm; by intros; simp only [norm_smul] end smul /-! ### Sum -/ section sum variables {ι : Type*} {A : ι → α → E'} {C : ι → ℝ} {s : finset ι} theorem is_O_with.sum (h : ∀ i ∈ s, is_O_with (C i) (A i) g l) : is_O_with (∑ i in s, C i) (λ x, ∑ i in s, A i x) g l := begin induction s using finset.induction_on with i s is IH, { simp only [is_O_with_zero', finset.sum_empty, forall_true_iff] }, { simp only [is, finset.sum_insert, not_false_iff], exact (h _ (finset.mem_insert_self i s)).add (IH (λ j hj, h _ (finset.mem_insert_of_mem hj))) } end theorem is_O.sum (h : ∀ i ∈ s, is_O (A i) g l) : is_O (λ x, ∑ i in s, A i x) g l := begin induction s using finset.induction_on with i s is IH, { simp only [is_O_zero, finset.sum_empty, forall_true_iff] }, { simp only [is, finset.sum_insert, not_false_iff], exact (h _ (finset.mem_insert_self i s)).add (IH (λ j hj, h _ (finset.mem_insert_of_mem hj))) } end theorem is_o.sum (h : ∀ i ∈ s, is_o (A i) g' l) : is_o (λ x, ∑ i in s, A i x) g' l := begin induction s using finset.induction_on with i s is IH, { simp only [is_o_zero, finset.sum_empty, forall_true_iff] }, { simp only [is, finset.sum_insert, not_false_iff], exact (h _ (finset.mem_insert_self i s)).add (IH (λ j hj, h _ (finset.mem_insert_of_mem hj))) } end end sum /-! ### Relation between `f = o(g)` and `f / g → 0` -/ theorem is_o.tendsto_0 {f g : α → 𝕜} {l : filter α} (h : is_o f g l) : tendsto (λ x, f x / (g x)) l (𝓝 0) := have eq₁ : is_o (λ x, f x / g x) (λ x, g x / g x) l, by simpa only [div_eq_mul_inv] using h.mul_is_O (is_O_refl _ _), have eq₂ : is_O (λ x, g x / g x) (λ x, (1 : 𝕜)) l, from is_O_of_le _ (λ x, by by_cases h : ∥g x∥ = 0; simp [h, zero_le_one]), (is_o_one_iff 𝕜).mp (eq₁.trans_is_O eq₂) theorem is_o_iff_tendsto' {f g : α → 𝕜} {l : filter α} (hgf : ∀ᶠ x in l, g x = 0 → f x = 0) : is_o f g l ↔ tendsto (λ x, f x / (g x)) l (𝓝 0) := iff.intro is_o.tendsto_0 $ λ h, (((is_o_one_iff _).mpr h).mul_is_O (is_O_refl g l)).congr' (hgf.mono $ λ x, div_mul_cancel_of_imp) (eventually_of_forall $ λ x, one_mul _) theorem is_o_iff_tendsto {f g : α → 𝕜} {l : filter α} (hgf : ∀ x, g x = 0 → f x = 0) : is_o f g l ↔ tendsto (λ x, f x / (g x)) l (𝓝 0) := ⟨λ h, h.tendsto_0, (is_o_iff_tendsto' (eventually_of_forall hgf)).2⟩ alias is_o_iff_tendsto' ↔ _ asymptotics.is_o_of_tendsto' alias is_o_iff_tendsto ↔ _ asymptotics.is_o_of_tendsto /-! ### Eventually (u / v) * v = u If `u` and `v` are linked by an `is_O_with` relation, then we eventually have `(u / v) * v = u`, even if `v` vanishes. -/ section eventually_mul_div_cancel variables {u v : α → 𝕜} lemma is_O_with.eventually_mul_div_cancel (h : is_O_with c u v l) : (u / v) * v =ᶠ[l] u := eventually.mono h.bound (λ y hy, div_mul_cancel_of_imp $ λ hv, by simpa [hv] using hy) /-- If `u = O(v)` along `l`, then `(u / v) * v = u` eventually at `l`. -/ lemma is_O.eventually_mul_div_cancel (h : is_O u v l) : (u / v) * v =ᶠ[l] u := let ⟨c, hc⟩ := h.is_O_with in hc.eventually_mul_div_cancel /-- If `u = o(v)` along `l`, then `(u / v) * v = u` eventually at `l`. -/ lemma is_o.eventually_mul_div_cancel (h : is_o u v l) : (u / v) * v =ᶠ[l] u := (h.forall_is_O_with zero_lt_one).eventually_mul_div_cancel end eventually_mul_div_cancel /-! ### Equivalent definitions of the form `∃ φ, u =ᶠ[l] φ * v` in a `normed_field`. -/ section exists_mul_eq variables {u v : α → 𝕜} /-- If `∥φ∥` is eventually bounded by `c`, and `u =ᶠ[l] φ * v`, then we have `is_O_with c u v l`. This does not require any assumptions on `c`, which is why we keep this version along with `is_O_with_iff_exists_eq_mul`. -/ lemma is_O_with_of_eq_mul (φ : α → 𝕜) (hφ : ∀ᶠ x in l, ∥φ x∥ ≤ c) (h : u =ᶠ[l] φ * v) : is_O_with c u v l := begin unfold is_O_with, refine h.symm.rw (λ x a, ∥a∥ ≤ c * ∥v x∥) (hφ.mono $ λ x hx, _), simp only [normed_field.norm_mul, pi.mul_apply], exact mul_le_mul_of_nonneg_right hx (norm_nonneg _) end lemma is_O_with_iff_exists_eq_mul (hc : 0 ≤ c) : is_O_with c u v l ↔ ∃ (φ : α → 𝕜) (hφ : ∀ᶠ x in l, ∥φ x∥ ≤ c), u =ᶠ[l] φ * v := begin split, { intro h, use (λ x, u x / v x), refine ⟨eventually.mono h.bound (λ y hy, _), h.eventually_mul_div_cancel.symm⟩, simpa using div_le_of_nonneg_of_le_mul (norm_nonneg _) hc hy }, { rintros ⟨φ, hφ, h⟩, exact is_O_with_of_eq_mul φ hφ h } end lemma is_O_with.exists_eq_mul (h : is_O_with c u v l) (hc : 0 ≤ c) : ∃ (φ : α → 𝕜) (hφ : ∀ᶠ x in l, ∥φ x∥ ≤ c), u =ᶠ[l] φ * v := (is_O_with_iff_exists_eq_mul hc).mp h lemma is_O_iff_exists_eq_mul : is_O u v l ↔ ∃ (φ : α → 𝕜) (hφ : l.is_bounded_under (≤) (norm ∘ φ)), u =ᶠ[l] φ * v := begin split, { rintros h, rcases h.exists_nonneg with ⟨c, hnnc, hc⟩, rcases hc.exists_eq_mul hnnc with ⟨φ, hφ, huvφ⟩, exact ⟨φ, ⟨c, hφ⟩, huvφ⟩ }, { rintros ⟨φ, ⟨c, hφ⟩, huvφ⟩, exact is_O_iff_is_O_with.2 ⟨c, is_O_with_of_eq_mul φ hφ huvφ⟩ } end alias is_O_iff_exists_eq_mul ↔ asymptotics.is_O.exists_eq_mul _ lemma is_o_iff_exists_eq_mul : is_o u v l ↔ ∃ (φ : α → 𝕜) (hφ : tendsto φ l (𝓝 0)), u =ᶠ[l] φ * v := begin split, { exact λ h, ⟨λ x, u x / v x, h.tendsto_0, h.eventually_mul_div_cancel.symm⟩ }, { unfold is_o, rintros ⟨φ, hφ, huvφ⟩ c hpos, rw normed_group.tendsto_nhds_zero at hφ, exact is_O_with_of_eq_mul _ ((hφ c hpos).mono $ λ x, le_of_lt) huvφ } end alias is_o_iff_exists_eq_mul ↔ asymptotics.is_o.exists_eq_mul _ end exists_mul_eq /-! ### Miscellanous lemmas -/ theorem div_is_bounded_under_of_is_O {α : Type*} {l : filter α} {f g : α → 𝕜} (h : is_O f g l) : is_bounded_under (≤) l (λ x, ∥f x / g x∥) := begin obtain ⟨c, hc⟩ := is_O_iff.mp h, refine ⟨max c 0, eventually_map.2 (filter.mem_of_superset hc (λ x hx, _))⟩, simp only [mem_set_of_eq, normed_field.norm_div] at ⊢ hx, by_cases hgx : g x = 0, { rw [hgx, norm_zero, div_zero, le_max_iff], exact or.inr le_rfl }, { exact le_max_iff.2 (or.inl ((div_le_iff (norm_pos_iff.2 hgx)).2 hx)) } end theorem is_O_iff_div_is_bounded_under {α : Type*} {l : filter α} {f g : α → 𝕜} (hgf : ∀ᶠ x in l, g x = 0 → f x = 0) : is_O f g l ↔ is_bounded_under (≤) l (λ x, ∥f x / g x∥) := begin refine ⟨div_is_bounded_under_of_is_O, λ h, _⟩, obtain ⟨c, hc⟩ := h, rw filter.eventually_iff at hgf hc, simp only [mem_set_of_eq, mem_map, normed_field.norm_div] at hc, refine is_O_iff.2 ⟨c, filter.eventually_of_mem (inter_mem hgf hc) (λ x hx, _)⟩, by_cases hgx : g x = 0, { simp [hx.1 hgx, hgx] }, { refine (div_le_iff (norm_pos_iff.2 hgx)).mp hx.2 }, end theorem is_O_of_div_tendsto_nhds {α : Type*} {l : filter α} {f g : α → 𝕜} (hgf : ∀ᶠ x in l, g x = 0 → f x = 0) (c : 𝕜) (H : filter.tendsto (f / g) l (𝓝 c)) : is_O f g l := (is_O_iff_div_is_bounded_under hgf).2 $ is_bounded_under_of_tendsto H lemma is_o.tendsto_zero_of_tendsto {α E 𝕜 : Type*} [normed_group E] [normed_field 𝕜] {u : α → E} {v : α → 𝕜} {l : filter α} {y : 𝕜} (huv : is_o u v l) (hv : tendsto v l (𝓝 y)) : tendsto u l (𝓝 0) := begin suffices h : is_o u (λ x, (1 : 𝕜)) l, { rwa is_o_one_iff at h }, exact huv.trans_is_O (is_O_one_of_tendsto 𝕜 hv), end theorem is_o_pow_pow {m n : ℕ} (h : m < n) : is_o (λ(x : 𝕜), x^n) (λx, x^m) (𝓝 0) := begin let p := n - m, have nmp : n = m + p := (add_sub_cancel_of_le (le_of_lt h)).symm, have : (λ(x : 𝕜), x^m) = (λx, x^m * 1), by simp only [mul_one], simp only [this, pow_add, nmp], refine is_O.mul_is_o (is_O_refl _ _) ((is_o_one_iff _).2 _), convert (continuous_pow p).tendsto (0 : 𝕜), exact (zero_pow (nat.sub_pos_of_lt h)).symm end theorem is_o_norm_pow_norm_pow {m n : ℕ} (h : m < n) : is_o (λ(x : E'), ∥x∥^n) (λx, ∥x∥^m) (𝓝 (0 : E')) := (is_o_pow_pow h).comp_tendsto tendsto_norm_zero theorem is_o_pow_id {n : ℕ} (h : 1 < n) : is_o (λ(x : 𝕜), x^n) (λx, x) (𝓝 0) := by { convert is_o_pow_pow h, simp only [pow_one] } theorem is_o_norm_pow_id {n : ℕ} (h : 1 < n) : is_o (λ(x : E'), ∥x∥^n) (λx, x) (𝓝 0) := by simpa only [pow_one, is_o_norm_right] using @is_o_norm_pow_norm_pow E' _ _ _ h theorem is_O_with.right_le_sub_of_lt_1 {f₁ f₂ : α → E'} (h : is_O_with c f₁ f₂ l) (hc : c < 1) : is_O_with (1 / (1 - c)) f₂ (λx, f₂ x - f₁ x) l := is_O_with.of_bound $ mem_of_superset h.bound $ λ x hx, begin simp only [mem_set_of_eq] at hx ⊢, rw [mul_comm, one_div, ← div_eq_mul_inv, le_div_iff, mul_sub, mul_one, mul_comm], { exact le_trans (sub_le_sub_left hx _) (norm_sub_norm_le _ _) }, { exact sub_pos.2 hc } end theorem is_O_with.right_le_add_of_lt_1 {f₁ f₂ : α → E'} (h : is_O_with c f₁ f₂ l) (hc : c < 1) : is_O_with (1 / (1 - c)) f₂ (λx, f₁ x + f₂ x) l := (h.neg_right.right_le_sub_of_lt_1 hc).neg_right.of_neg_left.congr rfl (λ x, rfl) (λ x, by rw [neg_sub, sub_neg_eq_add]) theorem is_o.right_is_O_sub {f₁ f₂ : α → E'} (h : is_o f₁ f₂ l) : is_O f₂ (λx, f₂ x - f₁ x) l := ((h.def' one_half_pos).right_le_sub_of_lt_1 one_half_lt_one).is_O theorem is_o.right_is_O_add {f₁ f₂ : α → E'} (h : is_o f₁ f₂ l) : is_O f₂ (λx, f₁ x + f₂ x) l := ((h.def' one_half_pos).right_le_add_of_lt_1 one_half_lt_one).is_O /-- If `f x = O(g x)` along `cofinite`, then there exists a positive constant `C` such that `∥f x∥ ≤ C * ∥g x∥` whenever `g x ≠ 0`. -/ theorem bound_of_is_O_cofinite (h : is_O f g' cofinite) : ∃ C > 0, ∀ ⦃x⦄, g' x ≠ 0 → ∥f x∥ ≤ C * ∥g' x∥ := begin rcases h.exists_pos with ⟨C, C₀, hC⟩, rw [is_O_with, eventually_cofinite] at hC, rcases (hC.to_finset.image (λ x, ∥f x∥ / ∥g' x∥)).exists_le with ⟨C', hC'⟩, have : ∀ x, C * ∥g' x∥ < ∥f x∥ → ∥f x∥ / ∥g' x∥ ≤ C', by simpa using hC', refine ⟨max C C', lt_max_iff.2 (or.inl C₀), λ x h₀, _⟩, rw [max_mul_of_nonneg _ _ (norm_nonneg _), le_max_iff, or_iff_not_imp_left, not_le], exact λ hx, (div_le_iff (norm_pos_iff.2 h₀)).1 (this _ hx) end theorem is_O_cofinite_iff (h : ∀ x, g' x = 0 → f' x = 0) : is_O f' g' cofinite ↔ ∃ C, ∀ x, ∥f' x∥ ≤ C * ∥g' x∥ := ⟨λ h', let ⟨C, C₀, hC⟩ := bound_of_is_O_cofinite h' in ⟨C, λ x, if hx : g' x = 0 then by simp [h _ hx, hx] else hC hx⟩, λ h, (is_O_top.2 h).mono le_top⟩ theorem bound_of_is_O_nat_at_top {f : ℕ → E} {g' : ℕ → E'} (h : is_O f g' at_top) : ∃ C > 0, ∀ ⦃x⦄, g' x ≠ 0 → ∥f x∥ ≤ C * ∥g' x∥ := bound_of_is_O_cofinite $ by rwa nat.cofinite_eq_at_top theorem is_O_nat_at_top_iff {f : ℕ → E'} {g : ℕ → F'} (h : ∀ x, g x = 0 → f x = 0) : is_O f g at_top ↔ ∃ C, ∀ x, ∥f x∥ ≤ C * ∥g x∥ := by rw [← nat.cofinite_eq_at_top, is_O_cofinite_iff h] theorem is_O_one_nat_at_top_iff {f : ℕ → E'} : is_O f (λ n, 1 : ℕ → ℝ) at_top ↔ ∃ C, ∀ n, ∥f n∥ ≤ C := iff.trans (is_O_nat_at_top_iff (λ n h, (one_ne_zero h).elim)) $ by simp only [norm_one, mul_one] theorem is_O_with_pi {ι : Type*} [fintype ι] {E' : ι → Type*} [Π i, normed_group (E' i)] {f : α → Π i, E' i} {C : ℝ} (hC : 0 ≤ C) : is_O_with C f g' l ↔ ∀ i, is_O_with C (λ x, f x i) g' l := have ∀ x, 0 ≤ C * ∥g' x∥, from λ x, mul_nonneg hC (norm_nonneg _), by simp only [is_O_with_iff, pi_norm_le_iff (this _), eventually_all] @[simp] theorem is_O_pi {ι : Type*} [fintype ι] {E' : ι → Type*} [Π i, normed_group (E' i)] {f : α → Π i, E' i} : is_O f g' l ↔ ∀ i, is_O (λ x, f x i) g' l := begin simp only [is_O_iff_eventually_is_O_with, ← eventually_all], exact eventually_congr (eventually_at_top.2 ⟨0, λ c, is_O_with_pi⟩) end @[simp] theorem is_o_pi {ι : Type*} [fintype ι] {E' : ι → Type*} [Π i, normed_group (E' i)] {f : α → Π i, E' i} : is_o f g' l ↔ ∀ i, is_o (λ x, f x i) g' l := begin simp only [is_o, is_O_with_pi, le_of_lt] { contextual := tt }, exact ⟨λ h i c hc, h hc i, λ h c hc i, h i hc⟩ end end asymptotics open asymptotics lemma summable_of_is_O {ι E} [normed_group E] [complete_space E] {f : ι → E} {g : ι → ℝ} (hg : summable g) (h : is_O f g cofinite) : summable f := let ⟨C, hC⟩ := h.is_O_with in summable_of_norm_bounded_eventually (λ x, C * ∥g x∥) (hg.abs.mul_left _) hC.bound lemma summable_of_is_O_nat {E} [normed_group E] [complete_space E] {f : ℕ → E} {g : ℕ → ℝ} (hg : summable g) (h : is_O f g at_top) : summable f := summable_of_is_O hg $ nat.cofinite_eq_at_top.symm ▸ h namespace local_homeomorph variables {α : Type*} {β : Type*} [topological_space α] [topological_space β] variables {E : Type*} [has_norm E] {F : Type*} [has_norm F] /-- Transfer `is_O_with` over a `local_homeomorph`. -/ lemma is_O_with_congr (e : local_homeomorph α β) {b : β} (hb : b ∈ e.target) {f : β → E} {g : β → F} {C : ℝ} : is_O_with C f g (𝓝 b) ↔ is_O_with C (f ∘ e) (g ∘ e) (𝓝 (e.symm b)) := ⟨λ h, h.comp_tendsto $ by { convert e.continuous_at (e.map_target hb), exact (e.right_inv hb).symm }, λ h, (h.comp_tendsto (e.continuous_at_symm hb)).congr' rfl ((e.eventually_right_inverse hb).mono $ λ x hx, congr_arg f hx) ((e.eventually_right_inverse hb).mono $ λ x hx, congr_arg g hx)⟩ /-- Transfer `is_O` over a `local_homeomorph`. -/ lemma is_O_congr (e : local_homeomorph α β) {b : β} (hb : b ∈ e.target) {f : β → E} {g : β → F} : is_O f g (𝓝 b) ↔ is_O (f ∘ e) (g ∘ e) (𝓝 (e.symm b)) := by { unfold is_O, exact exists_congr (λ C, e.is_O_with_congr hb) } /-- Transfer `is_o` over a `local_homeomorph`. -/ lemma is_o_congr (e : local_homeomorph α β) {b : β} (hb : b ∈ e.target) {f : β → E} {g : β → F} : is_o f g (𝓝 b) ↔ is_o (f ∘ e) (g ∘ e) (𝓝 (e.symm b)) := by { unfold is_o, exact (forall_congr $ λ c, forall_congr $ λ hc, e.is_O_with_congr hb) } end local_homeomorph namespace homeomorph variables {α : Type*} {β : Type*} [topological_space α] [topological_space β] variables {E : Type*} [has_norm E] {F : Type*} [has_norm F] open asymptotics /-- Transfer `is_O_with` over a `homeomorph`. -/ lemma is_O_with_congr (e : α ≃ₜ β) {b : β} {f : β → E} {g : β → F} {C : ℝ} : is_O_with C f g (𝓝 b) ↔ is_O_with C (f ∘ e) (g ∘ e) (𝓝 (e.symm b)) := e.to_local_homeomorph.is_O_with_congr trivial /-- Transfer `is_O` over a `homeomorph`. -/ lemma is_O_congr (e : α ≃ₜ β) {b : β} {f : β → E} {g : β → F} : is_O f g (𝓝 b) ↔ is_O (f ∘ e) (g ∘ e) (𝓝 (e.symm b)) := by { unfold is_O, exact exists_congr (λ C, e.is_O_with_congr) } /-- Transfer `is_o` over a `homeomorph`. -/ lemma is_o_congr (e : α ≃ₜ β) {b : β} {f : β → E} {g : β → F} : is_o f g (𝓝 b) ↔ is_o (f ∘ e) (g ∘ e) (𝓝 (e.symm b)) := by { unfold is_o, exact forall_congr (λ c, forall_congr (λ hc, e.is_O_with_congr)) } end homeomorph
66c95acfe98459062527bc8e8a5a825c3e77326e
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/Lean3Lib/data/rbtree/default_auto.lean
eb6d8c5b166bddd61ba453e8f09f0f2b2d21f226
[]
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
296
lean
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.Lean3Lib.data.rbtree.main namespace Mathlib end Mathlib
4a6b8a41d53db9a69b45539514a39acd55c8acc9
d7189ea2ef694124821b033e533f18905b5e87ef
/galois/list/map_accum_lemmas.lean
2be0add41902da047adab7739c55c211957efad3
[ "Apache-2.0" ]
permissive
digama0/lean-protocol-support
eaa7e6f8b8e0d5bbfff1f7f52bfb79a3b11b0f59
cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda
refs/heads/master
1,625,421,450,627
1,506,035,462,000
1,506,035,462,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
803
lean
import galois.nat.simplify_eq universe variable u namespace list variable { α : Type u} theorem map_accumr₂_append1 {α β γ φ : Type} (f : α → β → γ → γ × φ) (x : list α) (y : list β) (pr : length x = length y) (a : α) (b : β) (c : γ) : map_accumr₂ f (x ++ [a]) (y ++ [b]) c = let r := f a b c in let z := map_accumr₂ f x y (r^.fst) in ⟨ z^.fst, z^.snd ++ [r^.snd]⟩ := begin revert y, induction x with xh xr ind, -- Base case with x = nil { intros y pr, cases y with yh yr, { simp [map_accumr₂] }, { contradiction }, }, -- Inductive case with x = xh :: xr { intros y pr, cases y with yh yr, { contradiction }, { simp [nat.succ_add] at pr, simp [map_accumr₂, ind yr pr] }, } end end list
5fef2b34de47b9b0792d4d44b73a310ee833f958
f7c63613a4933f66368ef2802a50c417a46cddfc
/tests/lean/caching_user_attribute.lean
ca26b74a2aa6d5424e3ab6857d978a748182f402
[ "Apache-2.0" ]
permissive
avigad/lean
28cef71cd8c4eae53f342c87f81ca78d7cc75874
5410178203ab5ae854b5804586ace074ffd63aae
refs/heads/master
1,608,801,379,340
1,504,894,459,000
1,505,174,163,000
22,361,408
0
0
null
null
null
null
UTF-8
Lean
false
false
654
lean
@[user_attribute] meta def foo_attr : user_attribute string := { name := `foo, descr := "bar", cache_cfg := { mk_cache := λ ns, return $ string.join (list.map (λ n, to_string n ++ "\n") ns), dependencies := []} } attribute [foo] eq.refl eq.mp set_option trace.user_attributes_cache true run_cmd do s : string ← foo_attr.get_cache, tactic.trace s, s : string ← foo_attr.get_cache, tactic.trace s, foo_attr.set_param `eq.mpr () tt, s : string ← foo_attr.get_cache, tactic.trace s, tactic.set_basic_attribute `reducible ``eq.mp, -- should not affect [foo] cache s : string ← foo_attr.get_cache, tactic.trace s
ec281cb49b8f79bb2649096e948ae7816adbf7bd
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/run/subst1.lean
9103ddb92d2d2d182eda4ebdfb5a0c30eee3e277
[ "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
653
lean
-- set_option trace.Meta.Tactic.subst true theorem tst1 (x y z : Nat) : y = z → x = x → x = y → x = z := by intros h1 h2 h3 subst x assumption theorem tst2 (x y z : Nat) : y = z → x = z + y → x = z + z := by intros h1 h2 subst h1 subst h2 exact rfl def BV (n : Nat) : Type := { a : Array Bool // a.size = n } theorem tst3 (n m : Nat) (v : BV n) (w : BV m) (h1 : n = m) (h2 : forall (v1 v2 : BV n), v1 = v2) : v = cast (congrArg BV h1.symm) w := by subst h1 apply h2 theorem tst4 (n m : Nat) (v : BV n) (w : BV m) (h1 : n = m) (h2 : forall (v1 v2 : BV n), v1 = v2) : v = cast (congrArg BV h1.symm) w := by subst n apply h2
71ba48cabb22a3ad5d17bfcb2c6a7fc6423b7eb8
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/order/filter/partial.lean
a4e703fdfdba4a696e8afeb3c80a6853ca336ec7
[]
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
6,585
lean
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad Extends `tendsto` to relations and partial functions. -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.order.filter.basic import Mathlib.PostPort universes u v w namespace Mathlib namespace filter /- Relations. -/ def rmap {α : Type u} {β : Type v} (r : rel α β) (f : filter α) : filter β := mk (set_of fun (s : set β) => rel.core r s ∈ f) sorry sorry sorry theorem rmap_sets {α : Type u} {β : Type v} (r : rel α β) (f : filter α) : sets (rmap r f) = rel.core r ⁻¹' sets f := rfl @[simp] theorem mem_rmap {α : Type u} {β : Type v} (r : rel α β) (l : filter α) (s : set β) : s ∈ rmap r l ↔ rel.core r s ∈ l := iff.rfl @[simp] theorem rmap_rmap {α : Type u} {β : Type v} {γ : Type w} (r : rel α β) (s : rel β γ) (l : filter α) : rmap s (rmap r l) = rmap (rel.comp r s) l := sorry @[simp] theorem rmap_compose {α : Type u} {β : Type v} {γ : Type w} (r : rel α β) (s : rel β γ) : rmap s ∘ rmap r = rmap (rel.comp r s) := funext (rmap_rmap r s) def rtendsto {α : Type u} {β : Type v} (r : rel α β) (l₁ : filter α) (l₂ : filter β) := rmap r l₁ ≤ l₂ theorem rtendsto_def {α : Type u} {β : Type v} (r : rel α β) (l₁ : filter α) (l₂ : filter β) : rtendsto r l₁ l₂ ↔ ∀ (s : set β), s ∈ l₂ → rel.core r s ∈ l₁ := iff.rfl def rcomap {α : Type u} {β : Type v} (r : rel α β) (f : filter β) : filter α := mk (rel.image (fun (s : set β) (t : set α) => rel.core r s ⊆ t) (sets f)) sorry sorry sorry theorem rcomap_sets {α : Type u} {β : Type v} (r : rel α β) (f : filter β) : sets (rcomap r f) = rel.image (fun (s : set β) (t : set α) => rel.core r s ⊆ t) (sets f) := rfl @[simp] theorem rcomap_rcomap {α : Type u} {β : Type v} {γ : Type w} (r : rel α β) (s : rel β γ) (l : filter γ) : rcomap r (rcomap s l) = rcomap (rel.comp r s) l := sorry @[simp] theorem rcomap_compose {α : Type u} {β : Type v} {γ : Type w} (r : rel α β) (s : rel β γ) : rcomap r ∘ rcomap s = rcomap (rel.comp r s) := funext (rcomap_rcomap r s) theorem rtendsto_iff_le_comap {α : Type u} {β : Type v} (r : rel α β) (l₁ : filter α) (l₂ : filter β) : rtendsto r l₁ l₂ ↔ l₁ ≤ rcomap r l₂ := sorry -- Interestingly, there does not seem to be a way to express this relation using a forward map. -- Given a filter `f` on `α`, we want a filter `f'` on `β` such that `r.preimage s ∈ f` if -- and only if `s ∈ f'`. But the intersection of two sets satsifying the lhs may be empty. def rcomap' {α : Type u} {β : Type v} (r : rel α β) (f : filter β) : filter α := mk (rel.image (fun (s : set β) (t : set α) => rel.preimage r s ⊆ t) (sets f)) sorry sorry sorry @[simp] theorem mem_rcomap' {α : Type u} {β : Type v} (r : rel α β) (l : filter β) (s : set α) : s ∈ rcomap' r l ↔ ∃ (t : set β), ∃ (H : t ∈ l), rel.preimage r t ⊆ s := iff.rfl theorem rcomap'_sets {α : Type u} {β : Type v} (r : rel α β) (f : filter β) : sets (rcomap' r f) = rel.image (fun (s : set β) (t : set α) => rel.preimage r s ⊆ t) (sets f) := rfl @[simp] theorem rcomap'_rcomap' {α : Type u} {β : Type v} {γ : Type w} (r : rel α β) (s : rel β γ) (l : filter γ) : rcomap' r (rcomap' s l) = rcomap' (rel.comp r s) l := sorry @[simp] theorem rcomap'_compose {α : Type u} {β : Type v} {γ : Type w} (r : rel α β) (s : rel β γ) : rcomap' r ∘ rcomap' s = rcomap' (rel.comp r s) := funext (rcomap'_rcomap' r s) def rtendsto' {α : Type u} {β : Type v} (r : rel α β) (l₁ : filter α) (l₂ : filter β) := l₁ ≤ rcomap' r l₂ theorem rtendsto'_def {α : Type u} {β : Type v} (r : rel α β) (l₁ : filter α) (l₂ : filter β) : rtendsto' r l₁ l₂ ↔ ∀ (s : set β), s ∈ l₂ → rel.preimage r s ∈ l₁ := sorry theorem tendsto_iff_rtendsto {α : Type u} {β : Type v} (l₁ : filter α) (l₂ : filter β) (f : α → β) : tendsto f l₁ l₂ ↔ rtendsto (function.graph f) l₁ l₂ := sorry theorem tendsto_iff_rtendsto' {α : Type u} {β : Type v} (l₁ : filter α) (l₂ : filter β) (f : α → β) : tendsto f l₁ l₂ ↔ rtendsto' (function.graph f) l₁ l₂ := sorry /- Partial functions. -/ def pmap {α : Type u} {β : Type v} (f : α →. β) (l : filter α) : filter β := rmap (pfun.graph' f) l @[simp] theorem mem_pmap {α : Type u} {β : Type v} (f : α →. β) (l : filter α) (s : set β) : s ∈ pmap f l ↔ pfun.core f s ∈ l := iff.rfl def ptendsto {α : Type u} {β : Type v} (f : α →. β) (l₁ : filter α) (l₂ : filter β) := pmap f l₁ ≤ l₂ theorem ptendsto_def {α : Type u} {β : Type v} (f : α →. β) (l₁ : filter α) (l₂ : filter β) : ptendsto f l₁ l₂ ↔ ∀ (s : set β), s ∈ l₂ → pfun.core f s ∈ l₁ := iff.rfl theorem ptendsto_iff_rtendsto {α : Type u} {β : Type v} (l₁ : filter α) (l₂ : filter β) (f : α →. β) : ptendsto f l₁ l₂ ↔ rtendsto (pfun.graph' f) l₁ l₂ := iff.rfl theorem pmap_res {α : Type u} {β : Type v} (l : filter α) (s : set α) (f : α → β) : pmap (pfun.res f s) l = map f (l ⊓ principal s) := sorry theorem tendsto_iff_ptendsto {α : Type u} {β : Type v} (l₁ : filter α) (l₂ : filter β) (s : set α) (f : α → β) : tendsto f (l₁ ⊓ principal s) l₂ ↔ ptendsto (pfun.res f s) l₁ l₂ := sorry theorem tendsto_iff_ptendsto_univ {α : Type u} {β : Type v} (l₁ : filter α) (l₂ : filter β) (f : α → β) : tendsto f l₁ l₂ ↔ ptendsto (pfun.res f set.univ) l₁ l₂ := sorry def pcomap' {α : Type u} {β : Type v} (f : α →. β) (l : filter β) : filter α := rcomap' (pfun.graph' f) l def ptendsto' {α : Type u} {β : Type v} (f : α →. β) (l₁ : filter α) (l₂ : filter β) := l₁ ≤ rcomap' (pfun.graph' f) l₂ theorem ptendsto'_def {α : Type u} {β : Type v} (f : α →. β) (l₁ : filter α) (l₂ : filter β) : ptendsto' f l₁ l₂ ↔ ∀ (s : set β), s ∈ l₂ → pfun.preimage f s ∈ l₁ := rtendsto'_def (pfun.graph' f) l₁ l₂ theorem ptendsto_of_ptendsto' {α : Type u} {β : Type v} {f : α →. β} {l₁ : filter α} {l₂ : filter β} : ptendsto' f l₁ l₂ → ptendsto f l₁ l₂ := sorry theorem ptendsto'_of_ptendsto {α : Type u} {β : Type v} {f : α →. β} {l₁ : filter α} {l₂ : filter β} (h : pfun.dom f ∈ l₁) : ptendsto f l₁ l₂ → ptendsto' f l₁ l₂ := sorry
cb56d5f96f3c4ca46a8a29a2ed7981f1939793a2
02005f45e00c7ecf2c8ca5db60251bd1e9c860b5
/src/data/bool.lean
65b53d6c74fef3c4ab9f6748d1f31f9ca0de1294
[ "Apache-2.0" ]
permissive
anthony2698/mathlib
03cd69fe5c280b0916f6df2d07c614c8e1efe890
407615e05814e98b24b2ff322b14e8e3eb5e5d67
refs/heads/master
1,678,792,774,873
1,614,371,563,000
1,614,371,563,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
6,774
lean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura, Jeremy Avigad -/ /-! # booleans This file proves various trivial lemmas about booleans and their relation to decidable propositions. ## Notations This file introduces the notation `!b` for `bnot b`, the boolean "not". ## Tags bool, boolean, De Morgan -/ prefix `!`:90 := bnot namespace bool @[simp] theorem coe_sort_tt : coe_sort.{1 1} tt = true := eq_true_intro rfl @[simp] theorem coe_sort_ff : coe_sort.{1 1} ff = false := eq_false_intro ff_ne_tt @[simp] theorem to_bool_true {h} : @to_bool true h = tt := show _ = to_bool true, by congr @[simp] theorem to_bool_false {h} : @to_bool false h = ff := show _ = to_bool false, by congr @[simp] theorem to_bool_coe (b:bool) {h} : @to_bool b h = b := (show _ = to_bool b, by congr).trans (by cases b; refl) theorem coe_to_bool (p : Prop) [decidable p] : to_bool p ↔ p := to_bool_iff _ @[simp] lemma of_to_bool_iff {p : Prop} [decidable p] : to_bool p ↔ p := ⟨of_to_bool_true, _root_.to_bool_true⟩ @[simp] lemma tt_eq_to_bool_iff {p : Prop} [decidable p] : tt = to_bool p ↔ p := eq_comm.trans of_to_bool_iff @[simp] lemma ff_eq_to_bool_iff {p : Prop} [decidable p] : ff = to_bool p ↔ ¬ p := eq_comm.trans (to_bool_ff_iff _) @[simp] theorem to_bool_not (p : Prop) [decidable p] : to_bool (¬ p) = bnot (to_bool p) := by by_cases p; simp * @[simp] theorem to_bool_and (p q : Prop) [decidable p] [decidable q] : to_bool (p ∧ q) = p && q := by by_cases p; by_cases q; simp * @[simp] theorem to_bool_or (p q : Prop) [decidable p] [decidable q] : to_bool (p ∨ q) = p || q := by by_cases p; by_cases q; simp * @[simp] theorem to_bool_eq {p q : Prop} [decidable p] [decidable q] : to_bool p = to_bool q ↔ (p ↔ q) := ⟨λ h, (coe_to_bool p).symm.trans $ by simp [h], to_bool_congr⟩ lemma not_ff : ¬ ff := by simp @[simp] theorem default_bool : default bool = ff := rfl theorem dichotomy (b : bool) : b = ff ∨ b = tt := by cases b; simp @[simp] theorem forall_bool {p : bool → Prop} : (∀ b, p b) ↔ p ff ∧ p tt := ⟨λ h, by simp [h], λ ⟨h₁, h₂⟩ b, by cases b; assumption⟩ @[simp] theorem exists_bool {p : bool → Prop} : (∃ b, p b) ↔ p ff ∨ p tt := ⟨λ ⟨b, h⟩, by cases b; [exact or.inl h, exact or.inr h], λ h, by cases h; exact ⟨_, h⟩⟩ /-- If `p b` is decidable for all `b : bool`, then `∀ b, p b` is decidable -/ instance decidable_forall_bool {p : bool → Prop} [∀ b, decidable (p b)] : decidable (∀ b, p b) := decidable_of_decidable_of_iff and.decidable forall_bool.symm /-- If `p b` is decidable for all `b : bool`, then `∃ b, p b` is decidable -/ instance decidable_exists_bool {p : bool → Prop} [∀ b, decidable (p b)] : decidable (∃ b, p b) := decidable_of_decidable_of_iff or.decidable exists_bool.symm @[simp] theorem cond_ff {α} (t e : α) : cond ff t e = e := rfl @[simp] theorem cond_tt {α} (t e : α) : cond tt t e = t := rfl @[simp] theorem cond_to_bool {α} (p : Prop) [decidable p] (t e : α) : cond (to_bool p) t e = if p then t else e := by by_cases p; simp * theorem coe_bool_iff : ∀ {a b : bool}, (a ↔ b) ↔ a = b := dec_trivial theorem eq_tt_of_ne_ff : ∀ {a : bool}, a ≠ ff → a = tt := dec_trivial theorem eq_ff_of_ne_tt : ∀ {a : bool}, a ≠ tt → a = ff := dec_trivial theorem bor_comm : ∀ a b, a || b = b || a := dec_trivial @[simp] theorem bor_assoc : ∀ a b c, (a || b) || c = a || (b || c) := dec_trivial theorem bor_left_comm : ∀ a b c, a || (b || c) = b || (a || c) := dec_trivial theorem bor_inl {a b : bool} (H : a) : a || b := by simp [H] theorem bor_inr {a b : bool} (H : b) : a || b := by simp [H] theorem band_comm : ∀ a b, a && b = b && a := dec_trivial @[simp] theorem band_assoc : ∀ a b c, (a && b) && c = a && (b && c) := dec_trivial theorem band_left_comm : ∀ a b c, a && (b && c) = b && (a && c) := dec_trivial theorem band_elim_left : ∀ {a b : bool}, a && b → a := dec_trivial theorem band_intro : ∀ {a b : bool}, a → b → a && b := dec_trivial theorem band_elim_right : ∀ {a b : bool}, a && b → b := dec_trivial @[simp] theorem bnot_false : bnot ff = tt := rfl @[simp] theorem bnot_true : bnot tt = ff := rfl theorem eq_tt_of_bnot_eq_ff : ∀ {a : bool}, bnot a = ff → a = tt := dec_trivial theorem eq_ff_of_bnot_eq_tt : ∀ {a : bool}, bnot a = tt → a = ff := dec_trivial theorem bxor_comm : ∀ a b, bxor a b = bxor b a := dec_trivial @[simp] theorem bxor_assoc : ∀ a b c, bxor (bxor a b) c = bxor a (bxor b c) := dec_trivial theorem bxor_left_comm : ∀ a b c, bxor a (bxor b c) = bxor b (bxor a c) := dec_trivial @[simp] theorem bxor_bnot_left : ∀ a, bxor (!a) a = tt := dec_trivial @[simp] theorem bxor_bnot_right : ∀ a, bxor a (!a) = tt := dec_trivial @[simp] theorem bxor_bnot_bnot : ∀ a b, bxor (!a) (!b) = bxor a b := dec_trivial @[simp] theorem bxor_ff_left : ∀ a, bxor ff a = a := dec_trivial @[simp] theorem bxor_ff_right : ∀ a, bxor a ff = a := dec_trivial lemma bxor_iff_ne : ∀ {x y : bool}, bxor x y = tt ↔ x ≠ y := dec_trivial /-! ### De Morgan's laws for booleans-/ @[simp] lemma bnot_band : ∀ (a b : bool), !(a && b) = !a || !b := dec_trivial @[simp] lemma bnot_bor : ∀ (a b : bool), !(a || b) = !a && !b := dec_trivial lemma bnot_inj : ∀ {a b : bool}, !a = !b → a = b := dec_trivial end bool instance : linear_order bool := { le := λ a b, a = ff ∨ b = tt, le_refl := dec_trivial, le_trans := dec_trivial, le_antisymm := dec_trivial, le_total := dec_trivial, decidable_le := infer_instance, decidable_eq := infer_instance, decidable_lt := infer_instance } namespace bool @[simp] lemma ff_le {x : bool} : ff ≤ x := or.intro_left _ rfl @[simp] lemma le_tt {x : bool} : x ≤ tt := or.intro_right _ rfl @[simp] lemma ff_lt_tt : ff < tt := lt_of_le_of_ne ff_le ff_ne_tt /-- convert a `bool` to a `ℕ`, `false -> 0`, `true -> 1` -/ def to_nat (b : bool) : ℕ := cond b 1 0 /-- convert a `ℕ` to a `bool`, `0 -> false`, everything else -> `true` -/ def of_nat (n : ℕ) : bool := to_bool (n ≠ 0) lemma of_nat_le_of_nat {n m : ℕ} (h : n ≤ m) : of_nat n ≤ of_nat m := begin simp [of_nat]; cases nat.decidable_eq n 0; cases nat.decidable_eq m 0; simp only [to_bool], { subst m, have h := le_antisymm h (nat.zero_le _), contradiction }, { left, refl } end lemma to_nat_le_to_nat {b₀ b₁ : bool} (h : b₀ ≤ b₁) : to_nat b₀ ≤ to_nat b₁ := by cases h; subst h; [cases b₁, cases b₀]; simp [to_nat,nat.zero_le] lemma of_nat_to_nat (b : bool) : of_nat (to_nat b) = b := by cases b; simp only [of_nat,to_nat]; exact dec_trivial end bool
53a8bddd21a2670ec1c8f400894afe1a08fd63e0
dcf093fda1f51c094394c50e182cfb9dec39635a
/zf.lean
0cec52acd1af08ad407b6352ec8fb2882df6390a
[]
no_license
dselsam/cs103
7ac496d0293befca95d3045add91c5270a5d291f
31ab9784a6f65f226efb702a0da52f907c616a71
refs/heads/master
1,611,092,644,140
1,492,571,015,000
1,492,571,015,000
88,693,969
1
0
null
null
null
null
UTF-8
Lean
false
false
5,141
lean
import data.subtype namespace set constant set : Type.{1} constant empty : set constant pair : set → set → set constant filter : set → (set → Prop) → set constant bigunion : set → set constant powerset : set → set constant inf : set definition function := { f : set → set → Prop | ∀ x y z, f x y = f x z → y = z } constant map : function → set → set constant mem : set → set → Prop notation `∅` := empty infix `∈` := mem notation a ∉ b := ¬ mem a b definition subset (s1 s2 : set) := ∀ {u}, u ∈ s1 → u ∈ s2 infix `⊆` := subset definition singleton (s : set) := bigunion (pair s ∅) definition intersection (s1 s2 : set) := filter s1 (λ x, x ∈ s2) notation a ∩ b := intersection a b definition intersect_in_both : ∀ {s1 s2 : set} {x : set}, x ∈ s1 ∩ s2 → x ∈ s1 ∧ x ∈ s2 := sorry definition union (s1 s2 : set) := bigunion (pair s1 s2) notation a ∪ b := union a b -- Missing axiom axiom axiom_emptyset : ∀ x, x ∉ ∅ -- 1. Axiom of Extensionality: If X and Y have the same elements, then X=Y. axiom axiom_extensionality (X Y : set) : (∀ u, u ∈ X ↔ u ∈ Y) → X = Y -- 2. Axiom of the Unordered Pair: For any a and b there exists a set {a,b} that contains exactly a and b. (also called Axiom of Pairing) axiom axiom_pair : ∀ a b x, x ∈ pair a b ↔ (x = a ∨ x = b) -- 3. Axiom of Subsets: If phi is a property (with parameter p), then for any X and p there exists a set Y={u in X:phi(u,p)} that contains all those u in X that have the property phi. (also called Axiom of Separation or Axiom of Comprehension) axiom axiom_filter (X : set) : ∀ φ u, (u ∈ filter X φ) ↔ (u ∈ X ∧ φ u) -- 4. Axiom of the Sum Set: For any X there exists a set Y= union X, the union of all elements of X. (also called Axiom of Union) axiom axiom_unions (X : set) : ∀ u, u ∈ bigunion X ↔ ∃ z, z ∈ X ∧ u ∈ z -- 5. Axiom of the Power Set: For any X there exists a set Y=P(X), the set of all subsets of X. axiom axiom_powerset (X : set) : ∀ u, u ∈ powerset X ↔ u ⊆ X -- 6. Axiom of Infinity: There exists an infinite set. axiom axiom_infinity : ∅ ∈ inf ∧ ∀ x, x ∈ inf → pair x (singleton x) ∈ inf -- 7. Axiom of Replacement: If F is a function, then for any X there exists a set Y=F[X]={F(x):x in X}. -- (Note: this is a type theory function, not a set function. Would just require coercion and choice to make it set-theoretic) axiom axiom_replacement (X Y : set) : ∀ F y, y ∈ Y ↔ ∃ x, x ∈ X ∧ F x y -- 8. Axiom of Foundation: Every nonempty set has an in -minimal element. (also called Axiom of Regularity) axiom axiom_foundation : ∀ S, S ≠ ∅ → ∃ x, x ∈ S ∧ x ∩ S = ∅ end set namespace set_examples open set theorem subset_refl : ∀ A, A ⊆ A := -- Proof. Let A be an arbitrary set, and let x be an arbitrary member of A. assume A x `x ∈ A`, -- It is a tautology that x ∈ A → x ∈ A, so, by definition, A ⊆ A. show x ∈ A, from `x ∈ A` theorem subset_trans : ∀ (A B C : set), subset A B → subset B C → subset A C := -- Proof. Let A, B, and C be arbitrary sets such that A ⊆ B and B ⊆ C. assume A B C `A ⊆ B` `B ⊆ C`, -- Let x be an arbitrary member of A. assume x `x ∈ A`, -- Then x ∈ B because A ⊆ B. have x_in_B : x ∈ B, from `A ⊆ B` `x ∈ A`, -- But then x ∈ C since B ⊆ C. have x_in_C : x ∈ C, from `B ⊆ C` `x ∈ B`, -- Therefore, x ∈ C for all x ∈ A, so, by definition, A ⊆ C. show x ∈ C, from x_in_C theorem inter_subset : ∀ (A B : set), A ∩ B ⊆ A := -- Proof. Let A and B be arbitrary sets. Let x be an arbitrary member of A ∩ B. assume A B x `x ∈ A ∩ B`, -- Then, by definition, x ∈ A and x ∈ B, obtain `x ∈ A` `x ∈ B`, from intersect_in_both `x ∈ A ∩ B`, -- so, of course, x ∈ A. -- So, we have x ∈ A ∩ B → x ∈ A, so, by definition, A ∩ B ⊆ A. show x ∈ A, from `x ∈ A` theorem inter_sub_powerset : ∀ A B, A ∩ B ⊆ powerset A ∩ powerset B := -- Proof. Let A and B be arbitrary sets. assume A B, -- A ∩ B ⊆ A, so A ∩ B ∈ P(A) by the definition of powerset. have A ∩ B ∈ powerset A, from sorry, -- iff.elim_left (@axiom_powerset A (inter_subset A B)), -- Similarly, A ∩ B ∈ P(B). have A ∩ B ∈ powerset B, from sorry, -- same but with commutativity -- Hence A ∩ B ⊆ P(A) ∩ P(B). sorry lemma subset_eq : ∀ {A B}, A ⊆ B → B ⊆ A → A = B := sorry theorem powerset_inter_splits : ∀ A B, powerset (A ∩ B) = powerset A ∩ powerset B := -- Proof. Let A and B be arbitrary sets. assume A B, -- We prove set inclusion in both directions. -- First, to see that P(A ∩ B) ⊆ P(A) ∩ P(B), let S be an arbitrary member of P(A ∩ B). have H1 : powerset (A ∩ B) ⊆ powerset A ∩ powerset B, from assume S S_in_LHS, -- Then S ⊆ A ∩ B, have H1a : S ⊆ A ∩ B, from sorry, have H1b : A ∩ B ⊆ A, from sorry, have H1c : S ⊆ A, from sorry, have H1d : S ∈ powerset A, from sorry, sorry, sorry end set_examples
4cfccf2aaa04d7663bc89e6f2715e3e18f23c577
e00ea76a720126cf9f6d732ad6216b5b824d20a7
/src/algebra/group/type_tags.lean
5a5629fdae84b44e517a9d1c7143fa49449efd93
[ "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
3,437
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro Type tags `multiplicative` and `additive` that turn additive structures into multiplicative, and vice versa -/ import algebra.group.hom universes u v variables {α : Type u} {β : Type v} def additive (α : Type*) := α def multiplicative (α : Type*) := α instance [inhabited α] : inhabited (additive α) := ⟨(default _ : α)⟩ instance [inhabited α] : inhabited (multiplicative α) := ⟨(default _ : α)⟩ instance additive.has_add [has_mul α] : has_add (additive α) := { add := ((*) : α → α → α) } instance [has_add α] : has_mul (multiplicative α) := { mul := ((+) : α → α → α) } instance [semigroup α] : add_semigroup (additive α) := { add_assoc := @mul_assoc α _, ..additive.has_add } instance [add_semigroup α] : semigroup (multiplicative α) := { mul_assoc := @add_assoc α _, ..multiplicative.has_mul } instance [comm_semigroup α] : add_comm_semigroup (additive α) := { add_comm := @mul_comm _ _, ..additive.add_semigroup } instance [add_comm_semigroup α] : comm_semigroup (multiplicative α) := { mul_comm := @add_comm _ _, ..multiplicative.semigroup } instance [left_cancel_semigroup α] : add_left_cancel_semigroup (additive α) := { add_left_cancel := @mul_left_cancel _ _, ..additive.add_semigroup } instance [add_left_cancel_semigroup α] : left_cancel_semigroup (multiplicative α) := { mul_left_cancel := @add_left_cancel _ _, ..multiplicative.semigroup } instance [right_cancel_semigroup α] : add_right_cancel_semigroup (additive α) := { add_right_cancel := @mul_right_cancel _ _, ..additive.add_semigroup } instance [add_right_cancel_semigroup α] : right_cancel_semigroup (multiplicative α) := { mul_right_cancel := @add_right_cancel _ _, ..multiplicative.semigroup } instance [monoid α] : add_monoid (additive α) := { zero := (1 : α), zero_add := @one_mul _ _, add_zero := @mul_one _ _, ..additive.add_semigroup } instance [add_monoid α] : monoid (multiplicative α) := { one := (0 : α), one_mul := @zero_add _ _, mul_one := @add_zero _ _, ..multiplicative.semigroup } instance [comm_monoid α] : add_comm_monoid (additive α) := { add_comm := @mul_comm α _, ..additive.add_monoid } instance [add_comm_monoid α] : comm_monoid (multiplicative α) := { mul_comm := @add_comm α _, ..multiplicative.monoid } instance [group α] : add_group (additive α) := { neg := @has_inv.inv α _, add_left_neg := @mul_left_inv _ _, ..additive.add_monoid } instance [add_group α] : group (multiplicative α) := { inv := @has_neg.neg α _, mul_left_inv := @add_left_neg _ _, ..multiplicative.monoid } instance [comm_group α] : add_comm_group (additive α) := { add_comm := @mul_comm α _, ..additive.add_group } instance [add_comm_group α] : comm_group (multiplicative α) := { mul_comm := @add_comm α _, ..multiplicative.group } /-- Reinterpret `f : α →+ β` as `multiplicative α →* multiplicative β`. -/ def add_monoid_hom.to_multiplicative [add_monoid α] [add_monoid β] (f : α →+ β) : multiplicative α →* multiplicative β := ⟨f.1, f.2, f.3⟩ /-- Reinterpret `f : α →* β` as `additive α →+ additive β`. -/ def monoid_hom.to_additive [monoid α] [monoid β] (f : α →* β) : additive α →+ additive β := ⟨f.1, f.2, f.3⟩
951083d14bcacd616339e56112c7d6b3640b9332
2bafba05c98c1107866b39609d15e849a4ca2bb8
/src/week_1/kb_solutions/Part_D_relations_solutions.lean
58fb5376b27c64c0aff36bb801ce7673956b847e
[ "Apache-2.0" ]
permissive
ImperialCollegeLondon/formalising-mathematics
b54c83c94b5c315024ff09997fcd6b303892a749
7cf1d51c27e2038d2804561d63c74711924044a1
refs/heads/master
1,651,267,046,302
1,638,888,459,000
1,638,888,459,000
331,592,375
284
24
Apache-2.0
1,669,593,705,000
1,611,224,849,000
Lean
UTF-8
Lean
false
false
17,189
lean
import tactic /-! # Equivalence relations are the same as partitions In this file we prove that there's a bijection between the equivalence relations on a type, and the partitions of a type. Three sections: 1) partitions 2) equivalence classes 3) the proof ## Overview Say `α` is a type, and `R : α → α → Prop` is a binary relation on `α`. The following things are already in Lean: `reflexive R := ∀ (x : α), R x x` `symmetric R := ∀ ⦃x y : α⦄, R x y → R y x` `transitive R := ∀ ⦃x y z : α⦄, R x y → R y z → R x z` `equivalence R := reflexive R ∧ symmetric R ∧ transitive R` In the file below, we will define partitions of `α` and "build some interface" (i.e. prove some propositions). We will define equivalence classes and do the same thing. Finally, we will prove that there's a bijection between equivalence relations on `α` and partitions of `α`. -/ /- # 1) Partitions We define a partition, and prove some lemmas about partitions. Some I prove myself (not always using tactics) and some I leave for you. ## Definition of a partition Let `α` be a type. A *partition* on `α` is defined to be the following data: 1) A set C of subsets of α, called "blocks". 2) A hypothesis (i.e. a proof!) that all the blocks are non-empty. 3) A hypothesis that every term of type α is in one of the blocks. 4) A hypothesis that two blocks with non-empty intersection are equal. -/ /-- The structure of a partition on a Type α. -/ @[ext] structure partition (α : Type) := (C : set (set α)) (Hnonempty : ∀ X ∈ C, (X : set α).nonempty) (Hcover : ∀ a, ∃ X ∈ C, a ∈ X) (Hdisjoint : ∀ X Y ∈ C, (X ∩ Y : set α).nonempty → X = Y) /- ## Basic interface for partitions Here's the way notation works. If `α` is a type (i.e. a set) then a term `P` of type `partition α` is a partition of `α`, that is, a set of disjoint nonempty subsets of `α` whose union is `α`. The collection of sets underlying `P` is `P.C`, the proof that they're all nonempty is `P.Hnonempty` and so on. -/ namespace partition -- let α be a type, and fix a partition P on α. Let X and Y be subsets of α. variables {α : Type} {P : partition α} {X Y : set α} /-- If X and Y are blocks, and a is in X and Y, then X = Y. -/ theorem eq_of_mem (hX : X ∈ P.C) (hY : Y ∈ P.C) {a : α} (haX : a ∈ X) (haY : a ∈ Y) : X = Y := -- Proof: follows immediately from the disjointness hypothesis. P.Hdisjoint _ _ hX hY ⟨a, haX, haY⟩ /-- If a is in two blocks X and Y, and if b is in X, then b is in Y (as X=Y) -/ theorem mem_of_mem (hX : X ∈ P.C) (hY : Y ∈ P.C) {a b : α} (haX : a ∈ X) (haY : a ∈ Y) (hbX : b ∈ X) : b ∈ Y := begin -- you might want to start with `have hXY : X = Y` -- and prove it from the previous lemma have hXY : X = Y, { exact eq_of_mem hX hY haX haY }, -- we have b ∈ X as an assumption, and the goal is b ∈ Y. rw ← hXY, -- The goal is now b ∈ X assumption, end /-- Every term of type `α` is in one of the blocks for a partition `P`. -/ theorem mem_block (a : α) : ∃ X : set α, X ∈ P.C ∧ a ∈ X := begin -- an interesting way to start is -- `obtain ⟨X, hX, haX⟩ := P.Hcover a,` obtain ⟨X, hX, haX⟩ := P.Hcover a, -- `use` is the tactic to make progress with an `∃` goal use X, -- instead of `split` I'll just prove both things at once exact ⟨hX, haX⟩, end end partition /- # 2) Equivalence classes. We define equivalence classes and prove a few basic results about them. -/ section equivalence_classes /-! ## Definition of equivalence classes -/ -- Notation and variables for the equivalence class section: -- let α be a type, and let R be a binary relation on R. variables {α : Type} (R : α → α → Prop) /-- The equivalence class of `a` is the set of `b` related to `a`. -/ def cl (a : α) := {b : α | R b a} /-! ## Basic lemmas about equivalence classes -/ /-- Useful for rewriting -- `b` is in the equivalence class of `a` iff `b` is related to `a`. True by definition. -/ theorem mem_cl_iff {a b : α} : b ∈ cl R a ↔ R b a := begin -- true by definition refl end -- Assume now that R is an equivalence relation. variables {R} (hR : equivalence R) include hR /-- x is in cl(x) -/ lemma mem_cl_self (a : α) : a ∈ cl R a := begin -- Note that `hR : equivalence R` is a package of three things. -- You can extract the things with -- `rcases hR with ⟨hrefl, hsymm, htrans⟩,` or -- `obtain ⟨hrefl, hsymm, htrans⟩ := hR,` obtain ⟨hrefl, hsymm, htrans⟩ := hR, rw mem_cl_iff, -- not necessary (the proof is `refl`) but let's do it anyway -- now use reflexivity of `R`. apply hrefl, end lemma cl_sub_cl_of_mem_cl {a b : α} : a ∈ cl R b → cl R a ⊆ cl R b := begin -- remember `set.subset_def` says `X ⊆ Y ↔ ∀ a, a ∈ X → a ∈ Y intro hab, -- rw set.subset_def, -- not necessary because this is true by definition intros z hza, rw mem_cl_iff at hab hza ⊢, obtain ⟨hrefl, hsymm, htrans⟩ := hR, -- use transitivity of R to finish exact htrans hza hab, end lemma cl_eq_cl_of_mem_cl {a b : α} : a ∈ cl R b → cl R a = cl R b := begin intro hab, -- remember `set.subset.antisymm` says `X ⊆ Y → Y ⊆ X → X = Y` apply set.subset.antisymm, -- two goals now { -- first goal we proved already above exact cl_sub_cl_of_mem_cl hR hab}, { -- second goal we can reduce to b ∈ cl R a, i.e. R b a apply cl_sub_cl_of_mem_cl hR, obtain ⟨hrefl, hsymm, htrans⟩ := hR, -- and we know R a b so let's use symmetry exact hsymm hab } end end equivalence_classes -- section /-! # 3) The theorem Let `α` be a type (i.e. a collection of stucff). There is a bijection between equivalence relations on `α` and partitions of `α`. We prove this by writing down constructions in each direction and proving that the constructions are two-sided inverses of one another. -/ open partition example (α : Type) : {R : α → α → Prop // equivalence R} ≃ partition α := -- We define constructions (functions!) in both directions and prove that -- one is a two-sided inverse of the other { -- Here is the first construction, from equivalence -- relations to partitions. -- Let R be an equivalence relation. to_fun := λ R, { -- Let C be the set of equivalence classes for R. C := { B : set α | ∃ x : α, B = cl R.1 x}, -- I claim that C is a partition. We need to check the three -- hypotheses for a partition (`Hnonempty`, `Hcover` and `Hdisjoint`), -- so we need to supply three proofs. Hnonempty := begin cases R with R hR, -- If X is an equivalence class then X is nonempty. show ∀ (X : set α), (∃ (a : α), X = cl R a) → X.nonempty, -- let's assume X is the equivalence class of a rintros _ ⟨a, rfl⟩, -- we now have to prove that `cl R a` is nonempty, -- i.e. that there exists an element of `cl R a`. -- In particular this goal is an `∃`. Let's use `a`. use a, -- let's change the goal to R a a rw mem_cl_iff, -- comment out this line and the proof still works obtain ⟨hrefl, hsymm, htrans⟩ := hR, -- apply reflexivity of R apply hrefl, end, Hcover := begin cases R with R hR, -- The equivalence classes cover α show ∀ (a : α), ∃ (X : set α) (H : ∃ (b : α), X = cl R b), a ∈ X, -- let a be in α intro a, -- the goal is to prove that a is in some equivalence class. -- Let's use the equivalence class of a! use cl R a, -- Our goal is now of the form `P ∧ Q` split, { -- this first goal: we need to prove there's b such that cl a = cl b. -- let's use a! use a -- Lean tries `refl` by itself and it works }, { -- here we need to prove a ∈ cl R a, which by definition means -- that we need to prove `R a a`. Let's apply reflexivity of `R`. -- For a change I won't take `hR` apart, I'll just pull off the -- first term. apply hR.1 }, end, Hdisjoint := begin cases R with R hR, -- If two equivalence classes overlap, they are equal. show ∀ (X Y : set α), (∃ (a : α), X = cl R a) → (∃ (b : α), Y = cl _ b) → (X ∩ Y).nonempty → X = Y, -- let X and Y be equivalence classes of a and b respectively. -- Let's assume also that c is in X and Y. rintros X Y ⟨a, rfl⟩ ⟨b, rfl⟩ ⟨c, hca, hcb⟩, -- tidy up dsimp at *, -- we need to prove `cl R a = cl R b`. But we have proved a lemma -- here which is useful: apply cl_eq_cl_of_mem_cl hR, -- now we just have to rpove a ∈ cl R b, which is by definition -- R a b. Let's prove this by showing R a c and R c b -- and using transitivity. Let's start with transitivity. apply hR.2.2, -- ?m_1 is just Lean's way of writing an unknown variable. -- It's supposed to be `c`. change R a c, -- now it is `c`. -- Now we have two goals, `R a c` and `R c b`. -- Now let's use symmetry on the first goal. apply hR.2.1, -- now the first goal is `hca` exact hca, -- and the second is `hcb` exact hcb, end }, -- Conversely, say P is an partition. inv_fun := λ P, -- Let's define a binary relation `R` thus: -- `R a b` iff *every* block containing `a` also contains `b`. -- Because only one block contains a, this will work, -- and it turns out to be a nice way of thinking about it. ⟨λ a b, ∀ X ∈ P.C, a ∈ X → b ∈ X, begin -- I claim this is an equivalence relation. split, { -- It's reflexive show ∀ (a : α) (X : set α), X ∈ P.C → a ∈ X → a ∈ X, -- let a be in α and let X be a block such that a ∈ X intros a X hXC haX, -- now we have to prove a ∈ X but this is an assumption assumption, }, split, { -- it's symmetric show ∀ (a b : α), (∀ (X : set α), X ∈ P.C → a ∈ X → b ∈ X) → ∀ (X : set α), X ∈ P.C → b ∈ X → a ∈ X, -- say a and b are in α, say X is a block, and -- let `h` be the hypothesis that b is in every block which a is in. intros a b h X hX hbX, -- let `Y` be a block which `a` is in. obtain ⟨Y, hY, haY⟩ := P.Hcover a, -- apply `h` to hypothesis `Y` and deduce that `b ∈ Y` specialize h Y hY haY, -- now a,b ∈ Y and b ∈ X so a ∈ X by a previous lemma exact mem_of_mem hY hX h hbX haY, }, { -- it's transitive unfold transitive, show ∀ (a b c : α), (∀ (X : set α), X ∈ P.C → a ∈ X → b ∈ X) → (∀ (X : set α), X ∈ P.C → b ∈ X → c ∈ X) → ∀ (X : set α), X ∈ P.C → a ∈ X → c ∈ X, -- say a,b,c are in α, with `a ∈ X`, let `hbX` be the hypothesis that `b` is in -- every block which `a` is in, and let `hcX` be the hypothesis -- that `c` is in every block which `b` is in. intros a b c hbX hcX X hX haX, -- Our goal is `c ∈ X`. -- let's now use `hcX` to reduce it to `b ∈ X` apply hcX, assumption, -- and now let's use `hbX` to reduce it to `a ∈ X` apply hbX, assumption, -- but this is an assumption! assumption, } end⟩, -- If you start with the equivalence relation, and then make the partition -- and a new equivalence relation, you get back to where you started. left_inv := begin rintro ⟨R, hR⟩, -- Tidying up the mess... suffices : (λ (a b : α), ∀ (c : α), a ∈ cl R c → b ∈ cl R c) = R, simpa, -- ... you have to prove two binary relations are equal. ext a b, -- so you have to prove an if and only if. show (∀ (c : α), a ∈ cl R c → b ∈ cl R c) ↔ R a b, -- this is an ↔ so we can split it into → and ←. split, { -- Assume ∀ c, a ∈ cl c → b ∈ cl c intros hab, -- our goal is to prove R a b. Let's use symmetry apply hR.2.1, -- now let's use our assumption (with c = a, Lean guesses we mean this), apply hab, -- and now we have to prove a ∈ cl a, which is reflexivity apply hR.1, }, { -- conversely, let's assume `R a b` and say `c` is arbitrary -- such that a ∈ cl c` intros hab c hac, -- we have to prove b ∈ cl c, i.e. that `R b c`. Let's use transitivity apply hR.2.2, -- now we have to prove R b ? and R ? c for some ?. Let's let ? be a. change R b a, -- R b a follows from symmetry and R a b apply hR.2.1, exact hab, -- and R a c follows from a ∈ cl c (which is the same thing) exact hac, } end, -- Similarly, if you start with the partition, and then make the -- equivalence relation, and then construct the corresponding partition -- into equivalence classes, you have the same partition you started with. right_inv := begin -- Let P be a partition intro P, -- It suffices to prove that a subset X is in the original partition -- if and only if it's in the one made from the equivalence relation. ext X, show (∃ (a : α), X = cl _ a) ↔ X ∈ P.C, dsimp only, -- the goal is a bit intimidating. It says that there exists an a -- such that X is the equivalence class of a for this new complicated -- equivalence relation, if and only if X is a block. This is an ↔ -- goal. Let's prove both ways independently. split, { -- this way: assume X is the class of a for the equivalence relation -- we just made. rintro ⟨a, rfl⟩, -- We know P is a partition so let's take a block `X` containing `a`. obtain ⟨X, hX, haX⟩ := P.Hcover a, -- We know `X` is a block, i.e. `X ∈ P.C`. We're trying to prove -- that some strange equivalence class is in `P.C`. I claim that -- this class is `X`. So the proof should really be `hX`, except... convert hX, -- ... we have to prove that `X` is actually this messy class. -- How do we prove two sets are equal? We show that they have -- the same elements! So let's say `b` is in α. ext b, -- We need to show b is in the class of a iff b is in X. -- What does it mean for b to be in the equivalence class of a? rw mem_cl_iff, -- It means b and a are related, i.e. for every block, -- if b is in it then a is in it. Let's prove this iff by proving -- both directions. split, { -- assume a is in every block that b is in. intro haY, -- We know b is in a block, let's call it Y. obtain ⟨Y, hY, hbY⟩ := P.Hcover b, -- We know a is in every block that b is in, so a is in Y. specialize haY Y hY hbY, -- Now a ∈ X and a ∈ Y, so we must have X = Y. This means -- that our goal is technically proved by `hbY` convert hbY, -- except that we have to prove X = Y. But this is a previous lemma. exact eq_of_mem hX hY haX haY, }, { -- Conversely, assume b ∈ X. We need to prove that a is in every -- block which b is in. So let Y be a random block which b is in. intros hbX Y hY hbY, -- We want to show a ∈ Y. -- But we know a,b in X and b in Y so we're done by a previous -- lemma. apply mem_of_mem hX hY hbX hbY haX, } }, { -- conversely, let's assume X is a block. intro hX, -- We need to prove that X is the equivalence class of some `a`. -- Well, each block is nonempty, so let's take `a` in `X`. rcases P.Hnonempty X hX with ⟨a, ha⟩, -- The claim is that X is the equivalence class of `a`. use a, -- We now need to show two sets are equal, so let's use extensionality -- i.e. prove they have the same elements. Say b is in α. ext b, -- We have to prove b ∈ X ↔ b ∈ the equivalence class. Let's prove -- each direction separately. split, { -- Say b ∈ X. intro hbX, -- Let's prove it's in the equivalence class. What does it -- mean to be in an equivalence class? rw mem_cl_iff, -- we need to show that `a` is in every block which `b` is in. -- So let `Y` be any block which `b` is in. intros Y hY hbY, -- Now a,b ∈ X and b ∈ Y so we can deduce a ∈ Y from a previous lemma. exact mem_of_mem hX hY hbX hbY ha, }, { -- conversely, say b is in some equivalence class. What does this mean? rw mem_cl_iff, -- It means that `a` is in every block which `b` is in. intro haY, -- OK so b is in some block, let's call it `Y`. obtain ⟨Y, hY, hbY⟩ := P.Hcover b, -- This means `a` is in that block too. specialize haY Y hY hbY, -- and now a,b ∈ Y and a ∈ X so we can deduce b ∈ X from a previous lemma exact mem_of_mem hY hX haY ha hbY, } } end }
ca8a8c9700c56fb7952f150b8e652bf0b52814d6
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/topology/uniform_space/cauchy.lean
8e37a7986fd332752237508545052c6fcabffbe2
[]
no_license
AurelienSaue/Mathlib4_auto
f538cfd0980f65a6361eadea39e6fc639e9dae14
590df64109b08190abe22358fabc3eae000943f2
refs/heads/master
1,683,906,849,776
1,622,564,669,000
1,622,564,669,000
371,723,747
0
0
null
null
null
null
UTF-8
Lean
false
false
21,153
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.topology.uniform_space.basic import Mathlib.topology.bases import Mathlib.data.set.intervals.default import Mathlib.PostPort universes u v u_1 l namespace Mathlib /-! # Theory of Cauchy filters in uniform spaces. Complete uniform spaces. Totally bounded subsets. -/ /-- A filter `f` is Cauchy if for every entourage `r`, there exists an `s ∈ f` such that `s × s ⊆ r`. This is a generalization of Cauchy sequences, because if `a : ℕ → α` then the filter of sets containing cofinitely many of the `a n` is Cauchy iff `a` is a Cauchy sequence. -/ def cauchy {α : Type u} [uniform_space α] (f : filter α) := filter.ne_bot f ∧ filter.prod f f ≤ uniformity α /-- A set `s` is called *complete*, if any Cauchy filter `f` such that `s ∈ f` has a limit in `s` (formally, it satisfies `f ≤ 𝓝 x` for some `x ∈ s`). -/ def is_complete {α : Type u} [uniform_space α] (s : set α) := ∀ (f : filter α), cauchy f → f ≤ filter.principal s → ∃ (x : α), ∃ (H : x ∈ s), f ≤ nhds x theorem filter.has_basis.cauchy_iff {α : Type u} {β : Type v} [uniform_space α] {p : β → Prop} {s : β → set (α × α)} (h : filter.has_basis (uniformity α) p s) {f : filter α} : cauchy f ↔ filter.ne_bot f ∧ ∀ (i : β), p i → ∃ (t : set α), ∃ (H : t ∈ f), ∀ (x y : α), x ∈ t → y ∈ t → (x, y) ∈ s i := sorry theorem cauchy_iff' {α : Type u} [uniform_space α] {f : filter α} : cauchy f ↔ filter.ne_bot f ∧ ∀ (s : set (α × α)) (H : s ∈ uniformity α), ∃ (t : set α), ∃ (H : t ∈ f), ∀ (x y : α), x ∈ t → y ∈ t → (x, y) ∈ s := filter.has_basis.cauchy_iff (filter.basis_sets (uniformity α)) theorem cauchy_iff {α : Type u} [uniform_space α] {f : filter α} : cauchy f ↔ filter.ne_bot f ∧ ∀ (s : set (α × α)) (H : s ∈ uniformity α), ∃ (t : set α), ∃ (H : t ∈ f), set.prod t t ⊆ s := sorry theorem cauchy_map_iff {α : Type u} {β : Type v} [uniform_space α] {l : filter β} {f : β → α} : cauchy (filter.map f l) ↔ filter.ne_bot l ∧ filter.tendsto (fun (p : β × β) => (f (prod.fst p), f (prod.snd p))) (filter.prod l l) (uniformity α) := sorry theorem cauchy_map_iff' {α : Type u} {β : Type v} [uniform_space α] {l : filter β} [hl : filter.ne_bot l] {f : β → α} : cauchy (filter.map f l) ↔ filter.tendsto (fun (p : β × β) => (f (prod.fst p), f (prod.snd p))) (filter.prod l l) (uniformity α) := iff.trans cauchy_map_iff (and_iff_right hl) theorem cauchy.mono {α : Type u} [uniform_space α] {f : filter α} {g : filter α} [hg : filter.ne_bot g] (h_c : cauchy f) (h_le : g ≤ f) : cauchy g := { left := hg, right := le_trans (filter.prod_mono h_le h_le) (and.right h_c) } theorem cauchy.mono' {α : Type u} [uniform_space α] {f : filter α} {g : filter α} (h_c : cauchy f) (hg : filter.ne_bot g) (h_le : g ≤ f) : cauchy g := cauchy.mono h_c h_le theorem cauchy_nhds {α : Type u} [uniform_space α] {a : α} : cauchy (nhds a) := sorry theorem cauchy_pure {α : Type u} [uniform_space α] {a : α} : cauchy (pure a) := cauchy.mono cauchy_nhds (pure_le_nhds a) theorem filter.tendsto.cauchy_map {α : Type u} {β : Type v} [uniform_space α] {l : filter β} [filter.ne_bot l] {f : β → α} {a : α} (h : filter.tendsto f l (nhds a)) : cauchy (filter.map f l) := cauchy.mono cauchy_nhds h /-- The common part of the proofs of `le_nhds_of_cauchy_adhp` and `sequentially_complete.le_nhds_of_seq_tendsto_nhds`: if for any entourage `s` one can choose a set `t ∈ f` of diameter `s` such that it contains a point `y` with `(x, y) ∈ s`, then `f` converges to `x`. -/ theorem le_nhds_of_cauchy_adhp_aux {α : Type u} [uniform_space α] {f : filter α} {x : α} (adhs : ∀ (s : set (α × α)) (H : s ∈ uniformity α), ∃ (t : set α), ∃ (H : t ∈ f), set.prod t t ⊆ s ∧ ∃ (y : α), (x, y) ∈ s ∧ y ∈ t) : f ≤ nhds x := sorry /-- If `x` is an adherent (cluster) point for a Cauchy filter `f`, then it is a limit point for `f`. -/ theorem le_nhds_of_cauchy_adhp {α : Type u} [uniform_space α] {f : filter α} {x : α} (hf : cauchy f) (adhs : cluster_pt x f) : f ≤ nhds x := sorry theorem le_nhds_iff_adhp_of_cauchy {α : Type u} [uniform_space α] {f : filter α} {x : α} (hf : cauchy f) : f ≤ nhds x ↔ cluster_pt x f := { mp := fun (h : f ≤ nhds x) => cluster_pt.of_le_nhds' h (and.left hf), mpr := le_nhds_of_cauchy_adhp hf } theorem cauchy.map {α : Type u} {β : Type v} [uniform_space α] [uniform_space β] {f : filter α} {m : α → β} (hf : cauchy f) (hm : uniform_continuous m) : cauchy (filter.map m f) := { left := filter.ne_bot.map (and.left hf) m, right := le_trans (trans_rel_right LessEq filter.prod_map_map_eq (filter.map_mono (and.right hf))) hm } theorem cauchy.comap {α : Type u} {β : Type v} [uniform_space α] [uniform_space β] {f : filter β} {m : α → β} (hf : cauchy f) (hm : filter.comap (fun (p : α × α) => (m (prod.fst p), m (prod.snd p))) (uniformity β) ≤ uniformity α) [filter.ne_bot (filter.comap m f)] : cauchy (filter.comap m f) := { left := _inst_3, right := le_trans (trans_rel_right LessEq filter.prod_comap_comap_eq (filter.comap_mono (and.right hf))) hm } theorem cauchy.comap' {α : Type u} {β : Type v} [uniform_space α] [uniform_space β] {f : filter β} {m : α → β} (hf : cauchy f) (hm : filter.comap (fun (p : α × α) => (m (prod.fst p), m (prod.snd p))) (uniformity β) ≤ uniformity α) (hb : filter.ne_bot (filter.comap m f)) : cauchy (filter.comap m f) := cauchy.comap hf hm /-- Cauchy sequences. Usually defined on ℕ, but often it is also useful to say that a function defined on ℝ is Cauchy at +∞ to deduce convergence. Therefore, we define it in a type class that is general enough to cover both ℕ and ℝ, which are the main motivating examples. -/ def cauchy_seq {α : Type u} {β : Type v} [uniform_space α] [semilattice_sup β] (u : β → α) := cauchy (filter.map u filter.at_top) theorem cauchy_seq.mem_entourage {α : Type u} [uniform_space α] {ι : Type u_1} [Nonempty ι] [linear_order ι] {u : ι → α} (h : cauchy_seq u) {V : set (α × α)} (hV : V ∈ uniformity α) : ∃ (k₀ : ι), ∀ (i j : ι), k₀ ≤ i → k₀ ≤ j → (u i, u j) ∈ V := sorry theorem filter.tendsto.cauchy_seq {α : Type u} {β : Type v} [uniform_space α] [semilattice_sup β] [Nonempty β] {f : β → α} {x : α} (hx : filter.tendsto f filter.at_top (nhds x)) : cauchy_seq f := filter.tendsto.cauchy_map hx theorem cauchy_seq_iff_tendsto {α : Type u} {β : Type v} [uniform_space α] [Nonempty β] [semilattice_sup β] {u : β → α} : cauchy_seq u ↔ filter.tendsto (prod.map u u) filter.at_top (uniformity α) := sorry /-- If a Cauchy sequence has a convergent subsequence, then it converges. -/ theorem tendsto_nhds_of_cauchy_seq_of_subseq {α : Type u} {β : Type v} [uniform_space α] [semilattice_sup β] {u : β → α} (hu : cauchy_seq u) {ι : Type u_1} {f : ι → β} {p : filter ι} [filter.ne_bot p] (hf : filter.tendsto f p filter.at_top) {a : α} (ha : filter.tendsto (u ∘ f) p (nhds a)) : filter.tendsto u filter.at_top (nhds a) := le_nhds_of_cauchy_adhp hu (map_cluster_pt_of_comp hf ha) theorem filter.has_basis.cauchy_seq_iff {α : Type u} {β : Type v} [uniform_space α] {γ : Type u_1} [Nonempty β] [semilattice_sup β] {u : β → α} {p : γ → Prop} {s : γ → set (α × α)} (h : filter.has_basis (uniformity α) p s) : cauchy_seq u ↔ ∀ (i : γ), p i → ∃ (N : β), ∀ (m n : β), m ≥ N → n ≥ N → (u m, u n) ∈ s i := sorry theorem filter.has_basis.cauchy_seq_iff' {α : Type u} {β : Type v} [uniform_space α] {γ : Type u_1} [Nonempty β] [semilattice_sup β] {u : β → α} {p : γ → Prop} {s : γ → set (α × α)} (H : filter.has_basis (uniformity α) p s) : cauchy_seq u ↔ ∀ (i : γ), p i → ∃ (N : β), ∀ (n : β), n ≥ N → (u n, u N) ∈ s i := sorry theorem cauchy_seq_of_controlled {α : Type u} {β : Type v} [uniform_space α] [semilattice_sup β] [Nonempty β] (U : β → set (α × α)) (hU : ∀ (s : set (α × α)), s ∈ uniformity α → ∃ (n : β), U n ⊆ s) {f : β → α} (hf : ∀ {N m n : β}, N ≤ m → N ≤ n → (f m, f n) ∈ U N) : cauchy_seq f := sorry /-- A complete space is defined here using uniformities. A uniform space is complete if every Cauchy filter converges. -/ class complete_space (α : Type u) [uniform_space α] where complete : ∀ {f : filter α}, cauchy f → ∃ (x : α), f ≤ nhds x theorem complete_univ {α : Type u} [uniform_space α] [complete_space α] : is_complete set.univ := sorry theorem cauchy_prod {α : Type u} {β : Type v} [uniform_space α] [uniform_space β] {f : filter α} {g : filter β} : cauchy f → cauchy g → cauchy (filter.prod f g) := sorry protected instance complete_space.prod {α : Type u} {β : Type v} [uniform_space α] [uniform_space β] [complete_space α] [complete_space β] : complete_space (α × β) := complete_space.mk fun (f : filter (α × β)) (hf : cauchy f) => sorry /--If `univ` is complete, the space is a complete space -/ theorem complete_space_of_is_complete_univ {α : Type u} [uniform_space α] (h : is_complete set.univ) : complete_space α := sorry theorem complete_space_iff_is_complete_univ {α : Type u} [uniform_space α] : complete_space α ↔ is_complete set.univ := { mp := complete_univ, mpr := complete_space_of_is_complete_univ } theorem cauchy_iff_exists_le_nhds {α : Type u} [uniform_space α] [complete_space α] {l : filter α} [filter.ne_bot l] : cauchy l ↔ ∃ (x : α), l ≤ nhds x := sorry theorem cauchy_map_iff_exists_tendsto {α : Type u} {β : Type v} [uniform_space α] [complete_space α] {l : filter β} {f : β → α} [filter.ne_bot l] : cauchy (filter.map f l) ↔ ∃ (x : α), filter.tendsto f l (nhds x) := cauchy_iff_exists_le_nhds /-- A Cauchy sequence in a complete space converges -/ theorem cauchy_seq_tendsto_of_complete {α : Type u} {β : Type v} [uniform_space α] [semilattice_sup β] [complete_space α] {u : β → α} (H : cauchy_seq u) : ∃ (x : α), filter.tendsto u filter.at_top (nhds x) := complete_space.complete H /-- If `K` is a complete subset, then any cauchy sequence in `K` converges to a point in `K` -/ theorem cauchy_seq_tendsto_of_is_complete {α : Type u} {β : Type v} [uniform_space α] [semilattice_sup β] {K : set α} (h₁ : is_complete K) {u : β → α} (h₂ : ∀ (n : β), u n ∈ K) (h₃ : cauchy_seq u) : ∃ (v : α), ∃ (H : v ∈ K), filter.tendsto u filter.at_top (nhds v) := sorry theorem cauchy.le_nhds_Lim {α : Type u} [uniform_space α] [complete_space α] [Nonempty α] {f : filter α} (hf : cauchy f) : f ≤ nhds (Lim f) := le_nhds_Lim (complete_space.complete hf) theorem cauchy_seq.tendsto_lim {α : Type u} {β : Type v} [uniform_space α] [semilattice_sup β] [complete_space α] [Nonempty α] {u : β → α} (h : cauchy_seq u) : filter.tendsto u filter.at_top (nhds (lim filter.at_top u)) := cauchy.le_nhds_Lim h theorem is_closed.is_complete {α : Type u} [uniform_space α] [complete_space α] {s : set α} (h : is_closed s) : is_complete s := sorry /-- A set `s` is totally bounded if for every entourage `d` there is a finite set of points `t` such that every element of `s` is `d`-near to some element of `t`. -/ def totally_bounded {α : Type u} [uniform_space α] (s : set α) := ∀ (d : set (α × α)) (H : d ∈ uniformity α), ∃ (t : set α), set.finite t ∧ s ⊆ set.Union fun (y : α) => set.Union fun (H : y ∈ t) => set_of fun (x : α) => (x, y) ∈ d theorem totally_bounded_iff_subset {α : Type u} [uniform_space α] {s : set α} : totally_bounded s ↔ ∀ (d : set (α × α)) (H : d ∈ uniformity α), ∃ (t : set α), ∃ (H : t ⊆ s), set.finite t ∧ s ⊆ set.Union fun (y : α) => set.Union fun (H : y ∈ t) => set_of fun (x : α) => (x, y) ∈ d := sorry theorem totally_bounded_of_forall_symm {α : Type u} [uniform_space α] {s : set α} (h : ∀ (V : set (α × α)) (H : V ∈ uniformity α), symmetric_rel V → ∃ (t : set α), set.finite t ∧ s ⊆ set.Union fun (y : α) => set.Union fun (H : y ∈ t) => uniform_space.ball y V) : totally_bounded s := sorry theorem totally_bounded_subset {α : Type u} [uniform_space α] {s₁ : set α} {s₂ : set α} (hs : s₁ ⊆ s₂) (h : totally_bounded s₂) : totally_bounded s₁ := sorry theorem totally_bounded_empty {α : Type u} [uniform_space α] : totally_bounded ∅ := sorry /-- The closure of a totally bounded set is totally bounded. -/ theorem totally_bounded.closure {α : Type u} [uniform_space α] {s : set α} (h : totally_bounded s) : totally_bounded (closure s) := sorry /-- The image of a totally bounded set under a unifromly continuous map is totally bounded. -/ theorem totally_bounded.image {α : Type u} {β : Type v} [uniform_space α] [uniform_space β] {f : α → β} {s : set α} (hs : totally_bounded s) (hf : uniform_continuous f) : totally_bounded (f '' s) := sorry theorem ultrafilter.cauchy_of_totally_bounded {α : Type u} [uniform_space α] {s : set α} (f : ultrafilter α) (hs : totally_bounded s) (h : ↑f ≤ filter.principal s) : cauchy ↑f := sorry theorem totally_bounded_iff_filter {α : Type u} [uniform_space α] {s : set α} : totally_bounded s ↔ ∀ (f : filter α), filter.ne_bot f → f ≤ filter.principal s → ∃ (c : filter α), ∃ (H : c ≤ f), cauchy c := sorry theorem totally_bounded_iff_ultrafilter {α : Type u} [uniform_space α] {s : set α} : totally_bounded s ↔ ∀ (f : ultrafilter α), ↑f ≤ filter.principal s → cauchy ↑f := sorry theorem compact_iff_totally_bounded_complete {α : Type u} [uniform_space α] {s : set α} : is_compact s ↔ totally_bounded s ∧ is_complete s := sorry protected instance complete_of_compact {α : Type u} [uniform_space α] [compact_space α] : complete_space α := sorry theorem compact_of_totally_bounded_is_closed {α : Type u} [uniform_space α] [complete_space α] {s : set α} (ht : totally_bounded s) (hc : is_closed s) : is_compact s := iff.mpr compact_iff_totally_bounded_complete { left := ht, right := is_closed.is_complete hc } /-! ### Sequentially complete space In this section we prove that a uniform space is complete provided that it is sequentially complete (i.e., any Cauchy sequence converges) and its uniformity filter admits a countable generating set. In particular, this applies to (e)metric spaces, see the files `topology/metric_space/emetric_space` and `topology/metric_space/basic`. More precisely, we assume that there is a sequence of entourages `U_n` such that any other entourage includes one of `U_n`. Then any Cauchy filter `f` generates a decreasing sequence of sets `s_n ∈ f` such that `s_n × s_n ⊆ U_n`. Choose a sequence `x_n∈s_n`. It is easy to show that this is a Cauchy sequence. If this sequence converges to some `a`, then `f ≤ 𝓝 a`. -/ namespace sequentially_complete /-- An auxiliary sequence of sets approximating a Cauchy filter. -/ def set_seq_aux {α : Type u} [uniform_space α] {f : filter α} (hf : cauchy f) {U : ℕ → set (α × α)} (U_mem : ∀ (n : ℕ), U n ∈ uniformity α) (n : ℕ) : Subtype fun (s : set α) => ∃ (_x : s ∈ f), set.prod s s ⊆ U n := classical.indefinite_description (fun (s : set α) => ∃ (_x : s ∈ f), set.prod s s ⊆ U n) sorry /-- Given a Cauchy filter `f` and a sequence `U` of entourages, `set_seq` provides a sequence of monotonically decreasing sets `s n ∈ f` such that `(s n).prod (s n) ⊆ U`. -/ def set_seq {α : Type u} [uniform_space α] {f : filter α} (hf : cauchy f) {U : ℕ → set (α × α)} (U_mem : ∀ (n : ℕ), U n ∈ uniformity α) (n : ℕ) : set α := set.Inter fun (m : ℕ) => set.Inter fun (H : m ∈ set.Iic n) => subtype.val (set_seq_aux hf U_mem m) theorem set_seq_mem {α : Type u} [uniform_space α] {f : filter α} (hf : cauchy f) {U : ℕ → set (α × α)} (U_mem : ∀ (n : ℕ), U n ∈ uniformity α) (n : ℕ) : set_seq hf U_mem n ∈ f := iff.mpr (filter.bInter_mem_sets (set.finite_le_nat n)) fun (m : ℕ) (_x : m ∈ set_of fun (i : ℕ) => i ≤ n) => Exists.fst (subtype.property (set_seq_aux hf U_mem m)) theorem set_seq_mono {α : Type u} [uniform_space α] {f : filter α} (hf : cauchy f) {U : ℕ → set (α × α)} (U_mem : ∀ (n : ℕ), U n ∈ uniformity α) {m : ℕ} {n : ℕ} (h : m ≤ n) : set_seq hf U_mem n ⊆ set_seq hf U_mem m := set.bInter_subset_bInter_left fun (k : ℕ) (hk : k ∈ set.Iic m) => le_trans hk h theorem set_seq_sub_aux {α : Type u} [uniform_space α] {f : filter α} (hf : cauchy f) {U : ℕ → set (α × α)} (U_mem : ∀ (n : ℕ), U n ∈ uniformity α) (n : ℕ) : set_seq hf U_mem n ⊆ ↑(set_seq_aux hf U_mem n) := set.bInter_subset_of_mem set.right_mem_Iic theorem set_seq_prod_subset {α : Type u} [uniform_space α] {f : filter α} (hf : cauchy f) {U : ℕ → set (α × α)} (U_mem : ∀ (n : ℕ), U n ∈ uniformity α) {N : ℕ} {m : ℕ} {n : ℕ} (hm : N ≤ m) (hn : N ≤ n) : set.prod (set_seq hf U_mem m) (set_seq hf U_mem n) ⊆ U N := sorry /-- A sequence of points such that `seq n ∈ set_seq n`. Here `set_seq` is a monotonically decreasing sequence of sets `set_seq n ∈ f` with diameters controlled by a given sequence of entourages. -/ def seq {α : Type u} [uniform_space α] {f : filter α} (hf : cauchy f) {U : ℕ → set (α × α)} (U_mem : ∀ (n : ℕ), U n ∈ uniformity α) (n : ℕ) : α := classical.some sorry theorem seq_mem {α : Type u} [uniform_space α] {f : filter α} (hf : cauchy f) {U : ℕ → set (α × α)} (U_mem : ∀ (n : ℕ), U n ∈ uniformity α) (n : ℕ) : seq hf U_mem n ∈ set_seq hf U_mem n := classical.some_spec (filter.ne_bot.nonempty_of_mem (and.left hf) (set_seq_mem hf U_mem n)) theorem seq_pair_mem {α : Type u} [uniform_space α] {f : filter α} (hf : cauchy f) {U : ℕ → set (α × α)} (U_mem : ∀ (n : ℕ), U n ∈ uniformity α) {N : ℕ} {m : ℕ} {n : ℕ} (hm : N ≤ m) (hn : N ≤ n) : (seq hf U_mem m, seq hf U_mem n) ∈ U N := set_seq_prod_subset hf U_mem hm hn { left := seq_mem hf U_mem m, right := seq_mem hf U_mem n } theorem seq_is_cauchy_seq {α : Type u} [uniform_space α] {f : filter α} (hf : cauchy f) {U : ℕ → set (α × α)} (U_mem : ∀ (n : ℕ), U n ∈ uniformity α) (U_le : ∀ (s : set (α × α)), s ∈ uniformity α → ∃ (n : ℕ), U n ⊆ s) : cauchy_seq (seq hf U_mem) := cauchy_seq_of_controlled U U_le (seq_pair_mem hf U_mem) /-- If the sequence `sequentially_complete.seq` converges to `a`, then `f ≤ 𝓝 a`. -/ theorem le_nhds_of_seq_tendsto_nhds {α : Type u} [uniform_space α] {f : filter α} (hf : cauchy f) {U : ℕ → set (α × α)} (U_mem : ∀ (n : ℕ), U n ∈ uniformity α) (U_le : ∀ (s : set (α × α)), s ∈ uniformity α → ∃ (n : ℕ), U n ⊆ s) {a : α} (ha : filter.tendsto (seq hf U_mem) filter.at_top (nhds a)) : f ≤ nhds a := sorry end sequentially_complete namespace uniform_space /-- A uniform space is complete provided that (a) its uniformity filter has a countable basis; (b) any sequence satisfying a "controlled" version of the Cauchy condition converges. -/ theorem complete_of_convergent_controlled_sequences {α : Type u} [uniform_space α] (H : filter.is_countably_generated (uniformity α)) (U : ℕ → set (α × α)) (U_mem : ∀ (n : ℕ), U n ∈ uniformity α) (HU : ∀ (u : ℕ → α), (∀ (N m n : ℕ), N ≤ m → N ≤ n → (u m, u n) ∈ U N) → ∃ (a : α), filter.tendsto u filter.at_top (nhds a)) : complete_space α := sorry /-- A sequentially complete uniform space with a countable basis of the uniformity filter is complete. -/ theorem complete_of_cauchy_seq_tendsto {α : Type u} [uniform_space α] (H : filter.is_countably_generated (uniformity α)) (H' : ∀ (u : ℕ → α), cauchy_seq u → ∃ (a : α), filter.tendsto u filter.at_top (nhds a)) : complete_space α := sorry protected theorem first_countable_topology {α : Type u} [uniform_space α] (H : filter.is_countably_generated (uniformity α)) : topological_space.first_countable_topology α := sorry /-- A separable uniform space with countably generated uniformity filter is second countable: one obtains a countable basis by taking the balls centered at points in a dense subset, and with rational "radii" from a countable open symmetric antimono basis of `𝓤 α`. We do not register this as an instance, as there is already an instance going in the other direction from second countable spaces to separable spaces, and we want to avoid loops. -/ theorem second_countable_of_separable {α : Type u} [uniform_space α] (H : filter.is_countably_generated (uniformity α)) [topological_space.separable_space α] : topological_space.second_countable_topology α := sorry
9bbfdac4dae12f2c77e1e4a82334c674e338bdf9
a4673261e60b025e2c8c825dfa4ab9108246c32e
/stage0/src/Lean/Data/Json/FromToJson.lean
798d15a3317eac35cdcbec54da4705fb46ebfd96
[ "Apache-2.0" ]
permissive
jcommelin/lean4
c02dec0cc32c4bccab009285475f265f17d73228
2909313475588cc20ac0436e55548a4502050d0a
refs/heads/master
1,674,129,550,893
1,606,415,348,000
1,606,415,348,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
1,800
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 -/ import Lean.Data.Json.Basic namespace Lean universes u class FromJson (α : Type u) := (fromJson? : Json → Option α) export FromJson (fromJson?) class ToJson (α : Type u) := (toJson : α → Json) export ToJson (toJson) instance : FromJson Json := ⟨some⟩ instance : ToJson Json := ⟨id⟩ instance : FromJson JsonNumber := ⟨Json.getNum?⟩ instance : ToJson JsonNumber := ⟨Json.num⟩ -- looks like id, but there are coercions happening instance : FromJson Bool := ⟨Json.getBool?⟩ instance : ToJson Bool := ⟨fun b => b⟩ instance : FromJson Nat := ⟨Json.getNat?⟩ instance : ToJson Nat := ⟨fun n => n⟩ instance : FromJson Int := ⟨Json.getInt?⟩ instance : ToJson Int := ⟨fun n => Json.num n⟩ instance : FromJson String := ⟨Json.getStr?⟩ instance : ToJson String := ⟨fun s => s⟩ instance {α : Type u} [FromJson α] : FromJson (Array α) := ⟨fun j => match j with | Json.arr a => a.mapM fromJson? | _ => none⟩ instance {α : Type u} [ToJson α] : ToJson (Array α) := ⟨fun a => Json.arr (a.map toJson)⟩ namespace Json instance : FromJson Structured := ⟨fun j => match j with | arr a => Structured.arr a | obj o => Structured.obj o | _ => none⟩ instance : ToJson Structured := ⟨fun s => match s with | Structured.arr a => arr a | Structured.obj o => obj o⟩ def getObjValAs? (j : Json) (α : Type u) [FromJson α] (k : String) : Option α := (j.getObjVal? k).bind fromJson? def opt {α : Type u} [ToJson α] (k : String) : Option α → List (String × Json) | some o => [⟨k, toJson o⟩] | none => [] end Json end Lean
35fa6760705ae90448c9ade1fe7d902f9b4e584d
a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940
/stage0/src/Init/Data/Array/Subarray.lean
8c1880484fdea6dba714bf8c565a8f99e41115de
[ "Apache-2.0" ]
permissive
WojciechKarpiel/lean4
7f89706b8e3c1f942b83a2c91a3a00b05da0e65b
f6e1314fa08293dea66a329e05b6c196a0189163
refs/heads/master
1,686,633,402,214
1,625,821,189,000
1,625,821,258,000
384,640,886
0
0
Apache-2.0
1,625,903,617,000
1,625,903,026,000
null
UTF-8
Lean
false
false
4,268
lean
/- Copyright (c) 2020 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ prelude import Init.Data.Array.Basic universe u v w structure Subarray (α : Type u) where as : Array α start : Nat stop : Nat h₁ : start ≤ stop h₂ : stop ≤ as.size namespace Subarray @[inline] unsafe def forInUnsafe {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (s : Subarray α) (b : β) (f : α → β → m (ForInStep β)) : m β := let sz := USize.ofNat s.stop let rec @[specialize] loop (i : USize) (b : β) : m β := do if i < sz then let a := s.as.uget i lcProof match (← f a b) with | ForInStep.done b => pure b | ForInStep.yield b => loop (i+1) b else pure b loop (USize.ofNat s.start) b -- TODO: provide reference implementation @[implementedBy Subarray.forInUnsafe] protected constant forIn {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (s : Subarray α) (b : β) (f : α → β → m (ForInStep β)) : m β := pure b instance : ForIn m (Subarray α) α where forIn := Subarray.forIn @[inline] def foldlM {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (f : β → α → m β) (init : β) (as : Subarray α) : m β := as.as.foldlM f (init := init) (start := as.start) (stop := as.stop) @[inline] def foldrM {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (f : α → β → m β) (init : β) (as : Subarray α) : m β := as.as.foldrM f (init := init) (start := as.stop) (stop := as.start) @[inline] def anyM {α : Type u} {m : Type → Type w} [Monad m] (p : α → m Bool) (as : Subarray α) : m Bool := as.as.anyM p (start := as.start) (stop := as.stop) @[inline] def allM {α : Type u} {m : Type → Type w} [Monad m] (p : α → m Bool) (as : Subarray α) : m Bool := as.as.allM p (start := as.start) (stop := as.stop) @[inline] def forM {α : Type u} {m : Type v → Type w} [Monad m] (f : α → m PUnit) (as : Subarray α) : m PUnit := as.as.forM f (start := as.start) (stop := as.stop) @[inline] def forRevM {α : Type u} {m : Type v → Type w} [Monad m] (f : α → m PUnit) (as : Subarray α) : m PUnit := as.as.forRevM f (start := as.stop) (stop := as.start) @[inline] def foldl {α : Type u} {β : Type v} (f : β → α → β) (init : β) (as : Subarray α) : β := Id.run <| as.foldlM f (init := init) @[inline] def foldr {α : Type u} {β : Type v} (f : α → β → β) (init : β) (as : Subarray α) : β := Id.run <| as.foldrM f (init := init) @[inline] def any {α : Type u} (p : α → Bool) (as : Subarray α) : Bool := Id.run <| as.anyM p @[inline] def all {α : Type u} (p : α → Bool) (as : Subarray α) : Bool := Id.run <| as.allM p end Subarray namespace Array variable {α : Type u} def toSubarray (as : Array α) (start stop : Nat) : Subarray α := if h₂ : stop ≤ as.size then if h₁ : start ≤ stop then { as := as, start := start, stop := stop, h₁ := h₁, h₂ := h₂ } else { as := as, start := stop, stop := stop, h₁ := Nat.leRefl _, h₂ := h₂ } else if h₁ : start ≤ as.size then { as := as, start := start, stop := as.size, h₁ := h₁, h₂ := Nat.leRefl _ } else { as := as, start := as.size, stop := as.size, h₁ := Nat.leRefl _, h₂ := Nat.leRefl _ } def ofSubarray (s : Subarray α) : Array α := do let mut as := mkEmpty (s.stop - s.start) for a in s do as := as.push a return as def extract (as : Array α) (start stop : Nat) : Array α := ofSubarray (as.toSubarray start stop) instance : Coe (Subarray α) (Array α) := ⟨ofSubarray⟩ syntax:max term noWs "[" term ":" term "]" : term syntax:max term noWs "[" term ":" "]" : term syntax:max term noWs "[" ":" term "]" : term macro_rules | `($a[$start : $stop]) => `(Array.toSubarray $a $start $stop) | `($a[ : $stop]) => `(Array.toSubarray $a 0 $stop) | `($a[$start : ]) => `(let a := $a; Array.toSubarray a $start a.size) end Array def Subarray.toArray (s : Subarray α) : Array α := Array.ofSubarray s instance : HAppend (Subarray α) (Subarray α) (Array α) where hAppend x y := x.toArray ++ y.toArray
b54673bd891240c43d63f9117359c65caeef3b3d
aa3f8992ef7806974bc1ffd468baa0c79f4d6643
/tests/lean/run/sigma_no_confusion.lean
234517ac35c75217955bb03589433429ae049bd8
[ "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
1,247
lean
import data.sigma tools.tactic namespace sigma namespace manual definition no_confusion_type {A : Type} {B : A → Type} (P : Type) (v₁ v₂ : sigma B) : Type := rec_on v₁ (λ (a₁ : A) (b₁ : B a₁), rec_on v₂ (λ (a₂ : A) (b₂ : B a₂), (Π (eq₁ : a₁ = a₂), eq.rec_on eq₁ b₁ = b₂ → P) → P)) definition no_confusion {A : Type} {B : A → Type} {P : Type} {v₁ v₂ : sigma B} : v₁ = v₂ → no_confusion_type P v₁ v₂ := assume H₁₂ : v₁ = v₂, have aux : v₁ = v₁ → no_confusion_type P v₁ v₁, from assume H₁₁, rec_on v₁ (λ (a₁ : A) (b₁ : B a₁) (h : Π (eq₁ : a₁ = a₁), eq.rec_on eq₁ b₁ = b₁ → P), h rfl rfl), eq.rec_on H₁₂ aux H₁₂ end manual theorem sigma.mk.inj_1 {A : Type} {B : A → Type} {a₁ a₂ : A} {b₁ : B a₁} {b₂ : B a₂} (Heq : dpair a₁ b₁ = dpair a₂ b₂) : a₁ = a₂ := begin apply (no_confusion Heq), intros, assumption end theorem sigma.mk.inj_2 {A : Type} {B : A → Type} (a₁ a₂ : A) (b₁ : B a₁) (b₂ : B a₂) (Heq : dpair a₁ b₁ = dpair a₂ b₂) : b₁ == b₂ := begin apply (no_confusion Heq), intros, eassumption end end sigma
4f7323ec034bfb9f1c3a93219eeaf2f1fbdc4261
bb31430994044506fa42fd667e2d556327e18dfe
/src/set_theory/ordinal/topology.lean
3936f9e539058871c5f12d239251a98b1b6f223a
[ "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
9,705
lean
/- Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import set_theory.ordinal.arithmetic import topology.order.basic /-! ### Topology of ordinals We prove some miscellaneous results involving the order topology of ordinals. ### Main results * `ordinal.is_closed_iff_sup` / `ordinal.is_closed_iff_bsup`: A set of ordinals is closed iff it's closed under suprema. * `ordinal.is_normal_iff_strict_mono_and_continuous`: A characterization of normal ordinal functions. * `ordinal.enum_ord_is_normal_iff_is_closed`: The function enumerating the ordinals of a set is normal iff the set is closed. -/ noncomputable theory universes u v open cardinal order namespace ordinal variables {s : set ordinal.{u}} {a : ordinal.{u}} instance : topological_space ordinal.{u} := preorder.topology ordinal.{u} instance : order_topology ordinal.{u} := ⟨rfl⟩ theorem is_open_singleton_iff : is_open ({a} : set ordinal) ↔ ¬ is_limit a := begin refine ⟨λ h ha, _, λ ha, _⟩, { obtain ⟨b, c, hbc, hbc'⟩ := (mem_nhds_iff_exists_Ioo_subset' ⟨0, ordinal.pos_iff_ne_zero.2 ha.1⟩ ⟨_, lt_succ a⟩).1 (h.mem_nhds rfl), have hba := ha.2 b hbc.1, exact hba.ne (hbc' ⟨lt_succ b, hba.trans hbc.2⟩) }, { rcases zero_or_succ_or_limit a with rfl | ⟨b, hb⟩ | ha', { convert is_open_gt' (1 : ordinal), ext, exact ordinal.lt_one_iff_zero.symm }, { convert @is_open_Ioo _ _ _ _ b (a + 1), ext c, refine ⟨λ hc, _, _⟩, { rw set.mem_singleton_iff.1 hc, refine ⟨_, lt_succ a⟩, rw hb, exact lt_succ b }, { rintro ⟨hc, hc'⟩, apply le_antisymm (le_of_lt_succ hc'), rw hb, exact succ_le_of_lt hc } }, { exact (ha ha').elim } } end theorem is_open_iff : is_open s ↔ ∀ o ∈ s, is_limit o → ∃ a < o, set.Ioo a o ⊆ s := begin classical, refine ⟨_, λ h, _⟩, { rw is_open_iff_generate_intervals, intros h o hos ho, have ho₀ := ordinal.pos_iff_ne_zero.2 ho.1, induction h with t ht t u ht hu ht' hu' t ht H, { rcases ht with ⟨a, rfl | rfl⟩, { exact ⟨a, hos, λ b hb, hb.1⟩ }, { exact ⟨0, ho₀, λ b hb, hb.2.trans hos⟩ } }, { exact ⟨0, ho₀, λ b _, set.mem_univ b⟩ }, { rcases ht' hos.1 with ⟨a, ha, ha'⟩, rcases hu' hos.2 with ⟨b, hb, hb'⟩, exact ⟨_, max_lt ha hb, λ c hc, ⟨ ha' ⟨(le_max_left a b).trans_lt hc.1, hc.2⟩, hb' ⟨(le_max_right a b).trans_lt hc.1, hc.2⟩⟩⟩ }, { rcases hos with ⟨u, hu, hu'⟩, rcases H u hu hu' with ⟨a, ha, ha'⟩, exact ⟨a, ha, λ b hb, ⟨u, hu, ha' hb⟩⟩ } }, { let f : s → set ordinal := λ o, if ho : is_limit o.val then set.Ioo (classical.some (h o.val o.prop ho)) (o + 1) else {o.val}, have : ∀ a, is_open (f a) := λ a, begin change is_open (dite _ _ _), split_ifs, { exact is_open_Ioo }, { rwa is_open_singleton_iff } end, convert is_open_Union this, ext o, refine ⟨λ ho, set.mem_Union.2 ⟨⟨o, ho⟩, _⟩, _⟩, { split_ifs with ho', { refine ⟨_, lt_succ o⟩, cases classical.some_spec (h o ho ho') with H, exact H }, { exact set.mem_singleton o } }, { rintro ⟨t, ⟨a, ht⟩, hoa⟩, change dite _ _ _ = t at ht, split_ifs at ht with ha; subst ht, { cases classical.some_spec (h a.val a.prop ha) with H has, rcases lt_or_eq_of_le (le_of_lt_succ hoa.2) with hoa' | rfl, { exact has ⟨hoa.1, hoa'⟩ }, { exact a.prop } }, { convert a.prop } } } end theorem mem_closure_iff_sup : a ∈ closure s ↔ ∃ {ι : Type u} [nonempty ι] (f : ι → ordinal), (∀ i, f i ∈ s) ∧ sup.{u u} f = a := begin refine mem_closure_iff.trans ⟨λ h, _, _⟩, { by_cases has : a ∈ s, { exact ⟨punit, by apply_instance, λ _, a, λ _, has, sup_const a⟩ }, { have H := λ b (hba : b < a), h _ (@is_open_Ioo _ _ _ _ b (a + 1)) ⟨hba, lt_succ a⟩, let f : a.out.α → ordinal := λ i, classical.some (H (typein (<) i) (typein_lt_self i)), have hf : ∀ i, f i ∈ set.Ioo (typein (<) i) (a + 1) ∩ s := λ i, classical.some_spec (H _ _), rcases eq_zero_or_pos a with rfl | ha₀, { rcases h _ (is_open_singleton_iff.2 not_zero_is_limit) rfl with ⟨b, hb, hb'⟩, rw set.mem_singleton_iff.1 hb at *, exact (has hb').elim }, refine ⟨_, out_nonempty_iff_ne_zero.2 (ordinal.pos_iff_ne_zero.1 ha₀), f, λ i, (hf i).2, le_antisymm (sup_le (λ i, le_of_lt_succ (hf i).1.2)) _⟩, by_contra' h, cases H _ h with b hb, rcases eq_or_lt_of_le (le_of_lt_succ hb.1.2) with rfl | hba, { exact has hb.2 }, { have : b < f (enum (<) b (by rwa type_lt)) := begin have := (hf (enum (<) b (by rwa type_lt))).1.1, rwa typein_enum at this end, have : b ≤ sup.{u u} f := this.le.trans (le_sup f _), exact this.not_lt hb.1.1 } } }, { rintro ⟨ι, ⟨i⟩, f, hf, rfl⟩ t ht hat, cases eq_zero_or_pos (sup.{u u} f) with ha₀ ha₀, { rw ha₀ at hat, use [0, hat], convert hf i, exact (sup_eq_zero_iff.1 ha₀ i).symm }, rcases (mem_nhds_iff_exists_Ioo_subset' ⟨0, ha₀⟩ ⟨_, lt_succ _⟩).1 (ht.mem_nhds hat) with ⟨b, c, ⟨hab, hac⟩, hbct⟩, cases lt_sup.1 hab with i hi, exact ⟨_, hbct ⟨hi, (le_sup.{u u} f i).trans_lt hac⟩, hf i⟩ } end theorem mem_closed_iff_sup (hs : is_closed s) : a ∈ s ↔ ∃ {ι : Type u} (hι : nonempty ι) (f : ι → ordinal), (∀ i, f i ∈ s) ∧ sup.{u u} f = a := by rw [←mem_closure_iff_sup, hs.closure_eq] theorem mem_closure_iff_bsup : a ∈ closure s ↔ ∃ {o : ordinal} (ho : o ≠ 0) (f : Π a < o, ordinal), (∀ i hi, f i hi ∈ s) ∧ bsup.{u u} o f = a := mem_closure_iff_sup.trans ⟨ λ ⟨ι, ⟨i⟩, f, hf, ha⟩, ⟨_, λ h, (type_eq_zero_iff_is_empty.1 h).elim i, bfamily_of_family f, λ i hi, hf _, by rwa bsup_eq_sup⟩, λ ⟨o, ho, f, hf, ha⟩, ⟨_, out_nonempty_iff_ne_zero.2 ho, family_of_bfamily o f, λ i, hf _ _, by rwa sup_eq_bsup⟩⟩ theorem mem_closed_iff_bsup (hs : is_closed s) : a ∈ s ↔ ∃ {o : ordinal} (ho : o ≠ 0) (f : Π a < o, ordinal), (∀ i hi, f i hi ∈ s) ∧ bsup.{u u} o f = a := by rw [←mem_closure_iff_bsup, hs.closure_eq] theorem is_closed_iff_sup : is_closed s ↔ ∀ {ι : Type u} (hι : nonempty ι) (f : ι → ordinal), (∀ i, f i ∈ s) → sup.{u u} f ∈ s := begin use λ hs ι hι f hf, (mem_closed_iff_sup hs).2 ⟨ι, hι, f, hf, rfl⟩, rw ←closure_subset_iff_is_closed, intros h x hx, rcases mem_closure_iff_sup.1 hx with ⟨ι, hι, f, hf, rfl⟩, exact h hι f hf end theorem is_closed_iff_bsup : is_closed s ↔ ∀ {o : ordinal} (ho : o ≠ 0) (f : Π a < o, ordinal), (∀ i hi, f i hi ∈ s) → bsup.{u u} o f ∈ s := begin rw is_closed_iff_sup, refine ⟨λ H o ho f hf, H (out_nonempty_iff_ne_zero.2 ho) _ _, λ H ι hι f hf, _⟩, { exact λ i, hf _ _ }, { rw ←bsup_eq_sup, apply H (type_ne_zero_iff_nonempty.2 hι), exact λ i hi, hf _ } end theorem is_limit_of_mem_frontier (ha : a ∈ frontier s) : is_limit a := begin simp only [frontier_eq_closure_inter_closure, set.mem_inter_iff, mem_closure_iff] at ha, by_contra h, rw ←is_open_singleton_iff at h, rcases ha.1 _ h rfl with ⟨b, hb, hb'⟩, rcases ha.2 _ h rfl with ⟨c, hc, hc'⟩, rw set.mem_singleton_iff at *, subst hb, subst hc, exact hc' hb' end theorem is_normal_iff_strict_mono_and_continuous (f : ordinal.{u} → ordinal.{u}) : is_normal f ↔ strict_mono f ∧ continuous f := begin refine ⟨λ h, ⟨h.strict_mono, _⟩, _⟩, { rw continuous_def, intros s hs, rw is_open_iff at *, intros o ho ho', rcases hs _ ho (h.is_limit ho') with ⟨a, ha, has⟩, rw [←is_normal.bsup_eq.{u u} h ho', lt_bsup] at ha, rcases ha with ⟨b, hb, hab⟩, exact ⟨b, hb, λ c hc, set.mem_preimage.2 (has ⟨hab.trans (h.strict_mono hc.1), h.strict_mono hc.2⟩)⟩ }, { rw is_normal_iff_strict_mono_limit, rintro ⟨h, h'⟩, refine ⟨h, λ o ho a h, _⟩, suffices : o ∈ (f ⁻¹' set.Iic a), from set.mem_preimage.1 this, rw mem_closed_iff_sup (is_closed.preimage h' (@is_closed_Iic _ _ _ _ a)), exact ⟨_, out_nonempty_iff_ne_zero.2 ho.1, typein (<), λ i, h _ (typein_lt_self i), sup_typein_limit ho.2⟩ } end theorem enum_ord_is_normal_iff_is_closed (hs : s.unbounded (<)) : is_normal (enum_ord s) ↔ is_closed s := begin have Hs := enum_ord_strict_mono hs, refine ⟨λ h, is_closed_iff_sup.2 (λ ι hι f hf, _), λ h, (is_normal_iff_strict_mono_limit _).2 ⟨Hs, λ a ha o H, _⟩⟩, { let g : ι → ordinal.{u} := λ i, (enum_ord_order_iso hs).symm ⟨_, hf i⟩, suffices : enum_ord s (sup.{u u} g) = sup.{u u} f, { rw ←this, exact enum_ord_mem hs _ }, rw @is_normal.sup.{u u u} _ h ι g hι, congr, ext, change ((enum_ord_order_iso hs) _).val = f x, rw order_iso.apply_symm_apply }, { rw is_closed_iff_bsup at h, suffices : enum_ord s a ≤ bsup.{u u} a (λ b < a, enum_ord s b), from this.trans (bsup_le H), cases enum_ord_surjective hs _ (h ha.1 (λ b hb, enum_ord s b) (λ b hb, enum_ord_mem hs b)) with b hb, rw ←hb, apply Hs.monotone, by_contra' hba, apply (Hs (lt_succ b)).not_le, rw hb, exact le_bsup.{u u} _ _ (ha.2 _ hba) } end end ordinal
8346074b1828ccd9e9ebd5227458c19d19e04d7b
491068d2ad28831e7dade8d6dff871c3e49d9431
/tests/lean/run/app_builder.lean
cd5df96eb6cd26e3990731c69e653537952ababd
[ "Apache-2.0" ]
permissive
davidmueller13/lean
65a3ed141b4088cd0a268e4de80eb6778b21a0e9
c626e2e3c6f3771e07c32e82ee5b9e030de5b050
refs/heads/master
1,611,278,313,401
1,444,021,177,000
1,444,021,177,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
1,452
lean
definition a := 10 constant b : num constant c : num constant H1 : a = b constant H2 : b = c constant d : nat constant f : nat → nat constant g : nat → nat set_option pp.implicit true set_option pp.universes true set_option pp.notation false (* local env = get_env() local tc = non_irreducible_type_checker() local b = app_builder(tc) local a = Const("a") local c = Const("c") local d = Const("d") local f = Const("f") local g = Const("g") function tst(n, ...) local args = {...} local r = b:mk_app(n, unpack(args)) print(tostring(r) .. " : " .. tostring(tc:check(r))) return r end tst("eq", a, c) tst("eq", a, c) tst("eq", c, a) tst("eq", a, a) tst("eq", d, d) tst({"eq", "refl"}, a) tst({"eq", "refl"}, a) tst({"eq", "refl"}, d) tst({"eq", "refl"}, d) tst({"eq", "refl"}, c) tst({"eq", "refl"}, c, false) tst({"eq", "refl"}, a) local H1 = Const("H1") local H2 = Const("H2") tst({"eq", "trans"}, H1, H2) H1sy = tst({"eq", "symm"}, H1) H2sy = tst({"eq", "symm"}, H2) tst({"eq", "trans"}, H2sy, H1sy) tst({"heq", "refl"}, a) H1h = tst({"heq", "of_eq"}, H1) H2h = tst({"heq", "of_eq"}, H2) tst({"heq", "trans"}, H1h, H2h) tst({"heq", "symm"}, H1h) tst({"heq", "symm"}, H1h) tst({"heq"}, a, c) tst({"heq"}, a, d) tst({"heq"}, d, a) tst({"heq"}, a, c) tst({"heq"}, a, d) tst({"heq"}, d, a) tst({"eq", "refl"}, f) tst({"eq", "refl"}, g) tst("eq", f, g) tst("eq", g, f) *)
ccd72f326a6d2af26b333b18b0e38b7a490f054f
957a80ea22c5abb4f4670b250d55534d9db99108
/tests/lean/notation3.lean
5f1e6e5c37a3d7a2056cf852e770b0655638b270
[ "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
282
lean
-- inductive List (T : Type) : Type | nil {} : List | cons : T → List → List open List notation h :: t := cons h t notation `[` l:(foldr `, ` (h t, cons h t) nil) `]` := l constants a b : nat #check [a, b, b] #check (a, true, a = b, b) #check (a, b) #check [(1:nat), 2+2, 3]
952b317cb4bfab7a9285452b0ea37dcfad9466cc
80cc5bf14c8ea85ff340d1d747a127dcadeb966f
/src/category_theory/limits/connected.lean
280cf8b8e1199d8340dec14b2d8a49264cf9e79b
[ "Apache-2.0" ]
permissive
lacker/mathlib
f2439c743c4f8eb413ec589430c82d0f73b2d539
ddf7563ac69d42cfa4a1bfe41db1fed521bd795f
refs/heads/master
1,671,948,326,773
1,601,479,268,000
1,601,479,268,000
298,686,743
0
0
Apache-2.0
1,601,070,794,000
1,601,070,794,000
null
UTF-8
Lean
false
false
3,724
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 category_theory.limits.shapes.pullbacks import category_theory.limits.shapes.equalizers import category_theory.limits.preserves.basic import category_theory.is_connected /-! # Connected limits A connected limit is a limit whose shape is a connected category. We give examples of connected categories, and prove 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 × -)`. -/ noncomputable theory universes v₁ v₂ u₁ u₂ open category_theory category_theory.category category_theory.limits namespace category_theory section examples instance wide_pullback_shape_connected (J : Type v₁) : is_connected (wide_pullback_shape J) := begin apply is_connected.of_induct, introv _ t, cases j, { exact a }, { rwa t (wide_pullback_shape.hom.term j) } end instance wide_pushout_shape_connected (J : Type v₁) : is_connected (wide_pushout_shape J) := begin apply is_connected.of_induct, introv _ t, cases j, { exact a }, { rwa ← t (wide_pushout_shape.hom.init j) } end instance parallel_pair_inhabited : inhabited walking_parallel_pair := ⟨walking_parallel_pair.one⟩ instance parallel_pair_connected : is_connected (walking_parallel_pair) := begin apply is_connected.of_induct, introv _ t, cases j, { rwa t walking_parallel_pair_hom.left }, { assumption } end end examples local attribute [tidy] tactic.case_bash variables {C : Type u₂} [category.{v₂} C] variables [has_binary_products C] variables {J : Type v₂} [small_category J] namespace prod_preserves_connected_limits /-- (Impl). The obvious natural transformation from (X × K -) to K. -/ @[simps] def γ₂ {K : J ⥤ C} (X : C) : K ⋙ prod_functor.obj X ⟶ K := { app := λ Y, limits.prod.snd } /-- (Impl). The obvious natural transformation from (X × K -) to X -/ @[simps] def γ₁ {K : J ⥤ C} (X : C) : K ⋙ prod_functor.obj X ⟶ (functor.const J).obj X := { app := λ Y, limits.prod.fst } /-- (Impl). Given a cone for (X × K -), produce a cone for K using the natural transformation `γ₂` -/ @[simps] def forget_cone {X : C} {K : J ⥤ C} (s : cone (K ⋙ prod_functor.obj X)) : cone K := { X := s.X, π := s.π ≫ γ₂ X } end prod_preserves_connected_limits open prod_preserves_connected_limits /-- The functor `(X × -)` preserves any connected limit. Note that this functor does not preserve the two most obvious disconnected limits - that is, `(X × -)` does not preserve products or terminal object, eg `(X ⨯ A) ⨯ (X ⨯ B)` is not isomorphic to `X ⨯ (A ⨯ B)` and `X ⨯ 1` is not isomorphic to `1`. -/ noncomputable def prod_preserves_connected_limits [is_connected J] (X : C) : preserves_limits_of_shape J (prod_functor.obj X) := { preserves_limit := λ K, { preserves := λ c l, { lift := λ s, prod.lift (s.π.app (classical.arbitrary _) ≫ limits.prod.fst) (l.lift (forget_cone s)), fac' := λ s j, begin apply prod.hom_ext, { erw [assoc, limit.map_π, comp_id, limit.lift_π], exact (nat_trans_from_is_connected (s.π ≫ γ₁ X) j (classical.arbitrary _)).symm }, { simp [← l.fac (forget_cone s) j] } end, uniq' := λ s m L, begin apply prod.hom_ext, { erw [limit.lift_π, ← L (classical.arbitrary J), assoc, limit.map_π, comp_id], refl }, { rw limit.lift_π, apply l.uniq (forget_cone s), intro j, simp [← L j] } end } } } end category_theory
9957d14492a298da589520b3fad013fbe61c9ac1
a726f88081e44db9edfd14d32cfe9c4393ee56a4
/src/game/world8/level9.lean
485f4b711273fa3cb4fd02e380ea2b66be5b0ac1
[]
no_license
b-mehta/natural_number_game
80451bf10277adc89a55dbe8581692c36d822462
9faf799d0ab48ecbc89b3d70babb65ba64beee3b
refs/heads/master
1,598,525,389,186
1,573,516,674,000
1,573,516,674,000
217,339,684
0
0
null
1,571,933,100,000
1,571,933,099,000
null
UTF-8
Lean
false
false
858
lean
import mynat.definition -- hide import mynat.add -- hide import game.world8.level8 -- hide namespace mynat -- hide /- Axiom : zero_ne_succ (a : mynat) : 0 ≠ succ(a) -/ /- # Advanced Addition World ## Level 9: `succ_ne_zero` Levels 9 to 13 introduce the last axiom of Peano, namely that $0\not=\operatorname{succ}(a)$. The proof of this is called `zero_ne_succ a`. `zero_ne_succ (a : mynat) : 0 ≠ succ(a)` The `symmetry` tactic will turn any goal of the form `R x y` into `R y x`, if `R` is a symmetric binary relation (for example `=` or `≠`). In particular, you can prove `succ_ne_zero` below by first using `symmetry` and then `exact zero_ne_succ a`. -/ /- Theorem Zero is not the successor of any natural number. -/ theorem succ_ne_zero (a : mynat) : succ a ≠ 0 := begin [less_leaky] symmetry, exact zero_ne_succ a, end end mynat
fce7e1c9342cc28fd691ec5a6ca4744c905e368c
94e33a31faa76775069b071adea97e86e218a8ee
/src/measure_theory/measurable_space.lean
704510a8e3c8a9276c21b6c2f39f5e09f43bccb9
[ "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
62,696
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import algebra.indicator_function import data.prod.tprod import group_theory.coset import logic.equiv.fin import measure_theory.measurable_space_def import measure_theory.tactic import order.filter.lift /-! # Measurable spaces and measurable functions This file provides properties of measurable spaces and the functions and isomorphisms between them. The definition of a measurable space is in `measure_theory.measurable_space_def`. A measurable space is a set equipped with a σ-algebra, a collection of subsets closed under complementation and countable union. A function between measurable spaces is measurable if the preimage of each measurable subset is measurable. σ-algebras on a fixed set `α` form a complete lattice. Here we order σ-algebras by writing `m₁ ≤ m₂` if every set which is `m₁`-measurable is also `m₂`-measurable (that is, `m₁` is a subset of `m₂`). In particular, any collection of subsets of `α` generates a smallest σ-algebra which contains all of them. A function `f : α → β` induces a Galois connection between the lattices of σ-algebras on `α` and `β`. A measurable equivalence between measurable spaces is an equivalence which respects the σ-algebras, that is, for which both directions of the equivalence are measurable functions. We say that a filter `f` is measurably generated if every set `s ∈ f` includes a measurable set `t ∈ f`. This property is useful, e.g., to extract a measurable witness of `filter.eventually`. ## Notation * We write `α ≃ᵐ β` for measurable equivalences between the measurable spaces `α` and `β`. This should not be confused with `≃ₘ` which is used for diffeomorphisms between manifolds. ## Implementation notes Measurability of a function `f : α → β` between measurable spaces is defined in terms of the Galois connection induced by f. ## References * <https://en.wikipedia.org/wiki/Measurable_space> * <https://en.wikipedia.org/wiki/Sigma-algebra> * <https://en.wikipedia.org/wiki/Dynkin_system> ## Tags measurable space, σ-algebra, measurable function, measurable equivalence, dynkin system, π-λ theorem, π-system -/ open set encodable function equiv open_locale filter measure_theory variables {α β γ δ δ' : Type*} {ι : Sort*} {s t u : set α} namespace measurable_space section functors variables {m m₁ m₂ : measurable_space α} {m' : measurable_space β} {f : α → β} {g : β → α} /-- The forward image of a measurable space under a function. `map f m` contains the sets `s : set β` whose preimage under `f` is measurable. -/ protected def map (f : α → β) (m : measurable_space α) : measurable_space β := { measurable_set' := λ s, measurable_set[m] $ f ⁻¹' s, measurable_set_empty := m.measurable_set_empty, measurable_set_compl := assume s hs, m.measurable_set_compl _ hs, measurable_set_Union := assume f hf, by { rw preimage_Union, exact m.measurable_set_Union _ hf }} @[simp] lemma map_id : m.map id = m := measurable_space.ext $ assume s, iff.rfl @[simp] lemma map_comp {f : α → β} {g : β → γ} : (m.map f).map g = m.map (g ∘ f) := measurable_space.ext $ assume s, iff.rfl /-- The reverse image of a measurable space under a function. `comap f m` contains the sets `s : set α` such that `s` is the `f`-preimage of a measurable set in `β`. -/ protected def comap (f : α → β) (m : measurable_space β) : measurable_space α := { measurable_set' := λ s, ∃s', measurable_set[m] s' ∧ f ⁻¹' s' = s, measurable_set_empty := ⟨∅, m.measurable_set_empty, rfl⟩, measurable_set_compl := assume s ⟨s', h₁, h₂⟩, ⟨s'ᶜ, m.measurable_set_compl _ h₁, h₂ ▸ rfl⟩, measurable_set_Union := assume s hs, let ⟨s', hs'⟩ := classical.axiom_of_choice hs in ⟨⋃ i, s' i, m.measurable_set_Union _ (λ i, (hs' i).left), by simp [hs'] ⟩ } lemma comap_eq_generate_from (m : measurable_space β) (f : α → β) : m.comap f = generate_from {t | ∃ s, measurable_set s ∧ f ⁻¹' s = t} := by convert generate_from_measurable_set.symm @[simp] lemma comap_id : m.comap id = m := measurable_space.ext $ assume s, ⟨assume ⟨s', hs', h⟩, h ▸ hs', assume h, ⟨s, h, rfl⟩⟩ @[simp] lemma comap_comp {f : β → α} {g : γ → β} : (m.comap f).comap g = m.comap (f ∘ g) := measurable_space.ext $ assume s, ⟨assume ⟨t, ⟨u, h, hu⟩, ht⟩, ⟨u, h, ht ▸ hu ▸ rfl⟩, assume ⟨t, h, ht⟩, ⟨f ⁻¹' t, ⟨_, h, rfl⟩, ht⟩⟩ lemma comap_le_iff_le_map {f : α → β} : m'.comap f ≤ m ↔ m' ≤ m.map f := ⟨assume h s hs, h _ ⟨_, hs, rfl⟩, assume h s ⟨t, ht, heq⟩, heq ▸ h _ ht⟩ lemma gc_comap_map (f : α → β) : galois_connection (measurable_space.comap f) (measurable_space.map f) := assume f g, comap_le_iff_le_map lemma map_mono (h : m₁ ≤ m₂) : m₁.map f ≤ m₂.map f := (gc_comap_map f).monotone_u h lemma monotone_map : monotone (measurable_space.map f) := assume a b h, map_mono h lemma comap_mono (h : m₁ ≤ m₂) : m₁.comap g ≤ m₂.comap g := (gc_comap_map g).monotone_l h lemma monotone_comap : monotone (measurable_space.comap g) := assume a b h, comap_mono h @[simp] lemma comap_bot : (⊥ : measurable_space α).comap g = ⊥ := (gc_comap_map g).l_bot @[simp] lemma comap_sup : (m₁ ⊔ m₂).comap g = m₁.comap g ⊔ m₂.comap g := (gc_comap_map g).l_sup @[simp] lemma comap_supr {m : ι → measurable_space α} : (⨆i, m i).comap g = (⨆i, (m i).comap g) := (gc_comap_map g).l_supr @[simp] lemma map_top : (⊤ : measurable_space α).map f = ⊤ := (gc_comap_map f).u_top @[simp] lemma map_inf : (m₁ ⊓ m₂).map f = m₁.map f ⊓ m₂.map f := (gc_comap_map f).u_inf @[simp] lemma map_infi {m : ι → measurable_space α} : (⨅i, m i).map f = (⨅i, (m i).map f) := (gc_comap_map f).u_infi lemma comap_map_le : (m.map f).comap f ≤ m := (gc_comap_map f).l_u_le _ lemma le_map_comap : m ≤ (m.comap g).map g := (gc_comap_map g).le_u_l _ end functors lemma comap_generate_from {f : α → β} {s : set (set β)} : (generate_from s).comap f = generate_from (preimage f '' s) := le_antisymm (comap_le_iff_le_map.2 $ generate_from_le $ assume t hts, generate_measurable.basic _ $ mem_image_of_mem _ $ hts) (generate_from_le $ assume t ⟨u, hu, eq⟩, eq ▸ ⟨u, generate_measurable.basic _ hu, rfl⟩) end measurable_space section measurable_functions open measurable_space lemma measurable_iff_le_map {m₁ : measurable_space α} {m₂ : measurable_space β} {f : α → β} : measurable f ↔ m₂ ≤ m₁.map f := iff.rfl alias measurable_iff_le_map ↔ measurable.le_map measurable.of_le_map lemma measurable_iff_comap_le {m₁ : measurable_space α} {m₂ : measurable_space β} {f : α → β} : measurable f ↔ m₂.comap f ≤ m₁ := comap_le_iff_le_map.symm alias measurable_iff_comap_le ↔ measurable.comap_le measurable.of_comap_le lemma measurable.mono {ma ma' : measurable_space α} {mb mb' : measurable_space β} {f : α → β} (hf : @measurable α β ma mb f) (ha : ma ≤ ma') (hb : mb' ≤ mb) : @measurable α β ma' mb' f := λ t ht, ha _ $ hf $ hb _ ht @[measurability] lemma measurable_from_top [measurable_space β] {f : α → β} : measurable[⊤] f := λ s hs, trivial lemma measurable_generate_from [measurable_space α] {s : set (set β)} {f : α → β} (h : ∀ t ∈ s, measurable_set (f ⁻¹' t)) : @measurable _ _ _ (generate_from s) f := measurable.of_le_map $ generate_from_le h variables {f g : α → β} section typeclass_measurable_space variables [measurable_space α] [measurable_space β] [measurable_space γ] @[nontriviality, measurability] lemma subsingleton.measurable [subsingleton α] : measurable f := λ s hs, @subsingleton.measurable_set α _ _ _ @[nontriviality, measurability] lemma measurable_of_subsingleton_codomain [subsingleton β] (f : α → β) : measurable f := λ s hs, subsingleton.set_cases measurable_set.empty measurable_set.univ s @[to_additive] lemma measurable_one [has_one α] : measurable (1 : β → α) := @measurable_const _ _ _ _ 1 lemma measurable_of_empty [is_empty α] (f : α → β) : measurable f := subsingleton.measurable lemma measurable_of_empty_codomain [is_empty β] (f : α → β) : measurable f := by { haveI := function.is_empty f, exact measurable_of_empty f } /-- A version of `measurable_const` that assumes `f x = f y` for all `x, y`. This version works for functions between empty types. -/ lemma measurable_const' {f : β → α} (hf : ∀ x y, f x = f y) : measurable f := begin casesI is_empty_or_nonempty β, { exact measurable_of_empty f }, { convert measurable_const, exact funext (λ x, hf x h.some) } end lemma measurable_of_fintype [fintype α] [measurable_singleton_class α] (f : α → β) : measurable f := λ s hs, (f ⁻¹' s).to_finite.measurable_set end typeclass_measurable_space variables {m : measurable_space α} include m @[measurability] lemma measurable.iterate {f : α → α} (hf : measurable f) : ∀ n, measurable (f^[n]) | 0 := measurable_id | (n+1) := (measurable.iterate n).comp hf variables {mβ : measurable_space β} include mβ @[measurability] lemma measurable_set_preimage {t : set β} (hf : measurable f) (ht : measurable_set t) : measurable_set (f ⁻¹' t) := hf ht @[measurability] lemma measurable.piecewise {_ : decidable_pred (∈ s)} (hs : measurable_set s) (hf : measurable f) (hg : measurable g) : measurable (piecewise s f g) := begin intros t ht, rw piecewise_preimage, exact hs.ite (hf ht) (hg ht) end /-- this is slightly different from `measurable.piecewise`. It can be used to show `measurable (ite (x=0) 0 1)` by `exact measurable.ite (measurable_set_singleton 0) measurable_const measurable_const`, but replacing `measurable.ite` by `measurable.piecewise` in that example proof does not work. -/ lemma measurable.ite {p : α → Prop} {_ : decidable_pred p} (hp : measurable_set {a : α | p a}) (hf : measurable f) (hg : measurable g) : measurable (λ x, ite (p x) (f x) (g x)) := measurable.piecewise hp hf hg @[measurability] lemma measurable.indicator [has_zero β] (hf : measurable f) (hs : measurable_set s) : measurable (s.indicator f) := hf.piecewise hs measurable_const @[measurability, to_additive] lemma measurable_set_mul_support [has_one β] [measurable_singleton_class β] (hf : measurable f) : measurable_set (mul_support f) := hf (measurable_set_singleton 1).compl /-- If a function coincides with a measurable function outside of a countable set, it is measurable. -/ lemma measurable.measurable_of_countable_ne [measurable_singleton_class α] (hf : measurable f) (h : set.countable {x | f x ≠ g x}) : measurable g := begin assume t ht, have : g ⁻¹' t = (g ⁻¹' t ∩ {x | f x = g x}ᶜ) ∪ (g ⁻¹' t ∩ {x | f x = g x}), by simp [← inter_union_distrib_left], rw this, apply measurable_set.union (h.mono (inter_subset_right _ _)).measurable_set, have : g ⁻¹' t ∩ {x : α | f x = g x} = f ⁻¹' t ∩ {x : α | f x = g x}, by { ext x, simp {contextual := tt} }, rw this, exact (hf ht).inter h.measurable_set.of_compl, end end measurable_functions section constructions instance : measurable_space empty := ⊤ instance : measurable_space punit := ⊤ -- this also works for `unit` instance : measurable_space bool := ⊤ instance : measurable_space ℕ := ⊤ instance : measurable_space ℤ := ⊤ instance : measurable_space ℚ := ⊤ instance : measurable_singleton_class empty := ⟨λ _, trivial⟩ instance : measurable_singleton_class punit := ⟨λ _, trivial⟩ instance : measurable_singleton_class bool := ⟨λ _, trivial⟩ instance : measurable_singleton_class ℕ := ⟨λ _, trivial⟩ instance : measurable_singleton_class ℤ := ⟨λ _, trivial⟩ instance : measurable_singleton_class ℚ := ⟨λ _, trivial⟩ lemma measurable_to_encodable [measurable_space α] [encodable α] [measurable_space β] {f : β → α} (h : ∀ y, measurable_set (f ⁻¹' {f y})) : measurable f := begin assume s hs, rw [← bUnion_preimage_singleton], refine measurable_set.Union (λ y, measurable_set.Union_Prop $ λ hy, _), by_cases hyf : y ∈ range f, { rcases hyf with ⟨y, rfl⟩, apply h }, { simp only [preimage_singleton_eq_empty.2 hyf, measurable_set.empty] } end @[measurability] lemma measurable_unit [measurable_space α] (f : unit → α) : measurable f := measurable_from_top section nat variables [measurable_space α] @[measurability] lemma measurable_from_nat {f : ℕ → α} : measurable f := measurable_from_top lemma measurable_to_nat {f : α → ℕ} : (∀ y, measurable_set (f ⁻¹' {f y})) → measurable f := measurable_to_encodable lemma measurable_find_greatest' {p : α → ℕ → Prop} [∀ x, decidable_pred (p x)] {N : ℕ} (hN : ∀ k ≤ N, measurable_set {x | nat.find_greatest (p x) N = k}) : measurable (λ x, nat.find_greatest (p x) N) := measurable_to_nat $ λ x, hN _ N.find_greatest_le lemma measurable_find_greatest {p : α → ℕ → Prop} [∀ x, decidable_pred (p x)] {N} (hN : ∀ k ≤ N, measurable_set {x | p x k}) : measurable (λ x, nat.find_greatest (p x) N) := begin refine measurable_find_greatest' (λ k hk, _), simp only [nat.find_greatest_eq_iff, set_of_and, set_of_forall, ← compl_set_of], repeat { apply_rules [measurable_set.inter, measurable_set.const, measurable_set.Inter, measurable_set.Inter_Prop, measurable_set.compl, hN]; try { intros } } end lemma measurable_find {p : α → ℕ → Prop} [∀ x, decidable_pred (p x)] (hp : ∀ x, ∃ N, p x N) (hm : ∀ k, measurable_set {x | p x k}) : measurable (λ x, nat.find (hp x)) := begin refine measurable_to_nat (λ x, _), rw [preimage_find_eq_disjointed], exact measurable_set.disjointed hm _ end end nat section quotient variables [measurable_space α] [measurable_space β] instance {α} {r : α → α → Prop} [m : measurable_space α] : measurable_space (quot r) := m.map (quot.mk r) instance {α} {s : setoid α} [m : measurable_space α] : measurable_space (quotient s) := m.map quotient.mk' @[to_additive] instance _root_.quotient_group.measurable_space {G} [group G] [measurable_space G] (S : subgroup G) : measurable_space (G ⧸ S) := quotient.measurable_space lemma measurable_set_quotient {s : setoid α} {t : set (quotient s)} : measurable_set t ↔ measurable_set (quotient.mk' ⁻¹' t) := iff.rfl lemma measurable_from_quotient {s : setoid α} {f : quotient s → β} : measurable f ↔ measurable (f ∘ quotient.mk') := iff.rfl @[measurability] lemma measurable_quotient_mk [s : setoid α] : measurable (quotient.mk : α → quotient s) := λ s, id @[measurability] lemma measurable_quotient_mk' {s : setoid α} : measurable (quotient.mk' : α → quotient s) := λ s, id @[measurability] lemma measurable_quot_mk {r : α → α → Prop} : measurable (quot.mk r) := λ s, id @[to_additive] lemma quotient_group.measurable_coe {G} [group G] [measurable_space G] {S : subgroup G} : measurable (coe : G → G ⧸ S) := measurable_quotient_mk' attribute [measurability] quotient_group.measurable_coe quotient_add_group.measurable_coe @[to_additive] lemma quotient_group.measurable_from_quotient {G} [group G] [measurable_space G] {S : subgroup G} {f : G ⧸ S → α} : measurable f ↔ measurable (f ∘ (coe : G → G ⧸ S)) := measurable_from_quotient end quotient section subtype instance {α} {p : α → Prop} [m : measurable_space α] : measurable_space (subtype p) := m.comap (coe : _ → α) section variables [measurable_space α] @[measurability] lemma measurable_subtype_coe {p : α → Prop} : measurable (coe : subtype p → α) := measurable_space.le_map_comap instance {p : α → Prop} [measurable_singleton_class α] : measurable_singleton_class (subtype p) := { measurable_set_singleton := λ x, begin have : measurable_set {(x : α)} := measurable_set_singleton _, convert @measurable_subtype_coe α _ p _ this, ext y, simp [subtype.ext_iff], end } end variables {m : measurable_space α} {mβ : measurable_space β} include m lemma measurable_set.subtype_image {s : set α} {t : set s} (hs : measurable_set s) : measurable_set t → measurable_set ((coe : s → α) '' t) | ⟨u, (hu : measurable_set u), (eq : coe ⁻¹' u = t)⟩ := begin rw [← eq, subtype.image_preimage_coe], exact hu.inter hs end include mβ @[measurability] lemma measurable.subtype_coe {p : β → Prop} {f : α → subtype p} (hf : measurable f) : measurable (λ a : α, (f a : β)) := measurable_subtype_coe.comp hf @[measurability] lemma measurable.subtype_mk {p : β → Prop} {f : α → β} (hf : measurable f) {h : ∀ x, p (f x)} : measurable (λ x, (⟨f x, h x⟩ : subtype p)) := λ t ⟨s, hs⟩, hs.2 ▸ by simp only [← preimage_comp, (∘), subtype.coe_mk, hf hs.1] lemma measurable_of_measurable_union_cover {f : α → β} (s t : set α) (hs : measurable_set s) (ht : measurable_set t) (h : univ ⊆ s ∪ t) (hc : measurable (λ a : s, f a)) (hd : measurable (λ a : t, f a)) : measurable f := begin intros u hu, convert (hs.subtype_image (hc hu)).union (ht.subtype_image (hd hu)), change f ⁻¹' u = coe '' (coe ⁻¹' (f ⁻¹' u) : set s) ∪ coe '' (coe ⁻¹' (f ⁻¹' u) : set t), rw [image_preimage_eq_inter_range, image_preimage_eq_inter_range, subtype.range_coe, subtype.range_coe, ← inter_distrib_left, univ_subset_iff.1 h, inter_univ], end lemma measurable_of_restrict_of_restrict_compl {f : α → β} {s : set α} (hs : measurable_set s) (h₁ : measurable (s.restrict f)) (h₂ : measurable (sᶜ.restrict f)) : measurable f := measurable_of_measurable_union_cover s sᶜ hs hs.compl (union_compl_self s).ge h₁ h₂ lemma measurable.dite [∀ x, decidable (x ∈ s)] {f : s → β} (hf : measurable f) {g : sᶜ → β} (hg : measurable g) (hs : measurable_set s) : measurable (λ x, if hx : x ∈ s then f ⟨x, hx⟩ else g ⟨x, hx⟩) := measurable_of_restrict_of_restrict_compl hs (by simpa) (by simpa) lemma measurable_of_measurable_on_compl_finite [measurable_singleton_class α] {f : α → β} (s : set α) (hs : s.finite) (hf : measurable (sᶜ.restrict f)) : measurable f := begin letI : fintype s := finite.fintype hs, exact measurable_of_restrict_of_restrict_compl hs.measurable_set (measurable_of_fintype _) hf end lemma measurable_of_measurable_on_compl_singleton [measurable_singleton_class α] {f : α → β} (a : α) (hf : measurable ({x | x ≠ a}.restrict f)) : measurable f := measurable_of_measurable_on_compl_finite {a} (finite_singleton a) hf end subtype section prod /-- A `measurable_space` structure on the product of two measurable spaces. -/ def measurable_space.prod {α β} (m₁ : measurable_space α) (m₂ : measurable_space β) : measurable_space (α × β) := m₁.comap prod.fst ⊔ m₂.comap prod.snd instance {α β} [m₁ : measurable_space α] [m₂ : measurable_space β] : measurable_space (α × β) := m₁.prod m₂ @[measurability] lemma measurable_fst {ma : measurable_space α} {mb : measurable_space β} : measurable (prod.fst : α × β → α) := measurable.of_comap_le le_sup_left @[measurability] lemma measurable_snd {ma : measurable_space α} {mb : measurable_space β} : measurable (prod.snd : α × β → β) := measurable.of_comap_le le_sup_right variables {m : measurable_space α} {mβ : measurable_space β} {mγ : measurable_space γ} include m mβ mγ lemma measurable.fst {f : α → β × γ} (hf : measurable f) : measurable (λ a : α, (f a).1) := measurable_fst.comp hf lemma measurable.snd {f : α → β × γ} (hf : measurable f) : measurable (λ a : α, (f a).2) := measurable_snd.comp hf @[measurability] lemma measurable.prod {f : α → β × γ} (hf₁ : measurable (λ a, (f a).1)) (hf₂ : measurable (λ a, (f a).2)) : measurable f := measurable.of_le_map $ sup_le (by { rw [measurable_space.comap_le_iff_le_map, measurable_space.map_comp], exact hf₁ }) (by { rw [measurable_space.comap_le_iff_le_map, measurable_space.map_comp], exact hf₂ }) lemma measurable.prod_mk {β γ} {mβ : measurable_space β} {mγ : measurable_space γ} {f : α → β} {g : α → γ} (hf : measurable f) (hg : measurable g) : measurable (λ a : α, (f a, g a)) := measurable.prod hf hg lemma measurable.prod_map [measurable_space δ] {f : α → β} {g : γ → δ} (hf : measurable f) (hg : measurable g) : measurable (prod.map f g) := (hf.comp measurable_fst).prod_mk (hg.comp measurable_snd) omit mγ lemma measurable_prod_mk_left {x : α} : measurable (@prod.mk _ β x) := measurable_const.prod_mk measurable_id lemma measurable_prod_mk_right {y : β} : measurable (λ x : α, (x, y)) := measurable_id.prod_mk measurable_const include mγ lemma measurable.of_uncurry_left {f : α → β → γ} (hf : measurable (uncurry f)) {x : α} : measurable (f x) := hf.comp measurable_prod_mk_left lemma measurable.of_uncurry_right {f : α → β → γ} (hf : measurable (uncurry f)) {y : β} : measurable (λ x, f x y) := hf.comp measurable_prod_mk_right lemma measurable_prod {f : α → β × γ} : measurable f ↔ measurable (λ a, (f a).1) ∧ measurable (λ a, (f a).2) := ⟨λ hf, ⟨measurable_fst.comp hf, measurable_snd.comp hf⟩, λ h, measurable.prod h.1 h.2⟩ omit mγ @[measurability] lemma measurable_swap : measurable (prod.swap : α × β → β × α) := measurable.prod measurable_snd measurable_fst lemma measurable_swap_iff {mγ : measurable_space γ} {f : α × β → γ} : measurable (f ∘ prod.swap) ↔ measurable f := ⟨λ hf, by { convert hf.comp measurable_swap, ext ⟨x, y⟩, refl }, λ hf, hf.comp measurable_swap⟩ @[measurability] lemma measurable_set.prod {s : set α} {t : set β} (hs : measurable_set s) (ht : measurable_set t) : measurable_set (s ×ˢ t) := measurable_set.inter (measurable_fst hs) (measurable_snd ht) lemma measurable_set_prod_of_nonempty {s : set α} {t : set β} (h : (s ×ˢ t : set _).nonempty) : measurable_set (s ×ˢ t) ↔ measurable_set s ∧ measurable_set t := begin rcases h with ⟨⟨x, y⟩, hx, hy⟩, refine ⟨λ hst, _, λ h, h.1.prod h.2⟩, have : measurable_set ((λ x, (x, y)) ⁻¹' s ×ˢ t) := measurable_prod_mk_right hst, have : measurable_set (prod.mk x ⁻¹' s ×ˢ t) := measurable_prod_mk_left hst, simp * at * end lemma measurable_set_prod {s : set α} {t : set β} : measurable_set (s ×ˢ t) ↔ (measurable_set s ∧ measurable_set t) ∨ s = ∅ ∨ t = ∅ := begin cases (s ×ˢ t : set _).eq_empty_or_nonempty with h h, { simp [h, prod_eq_empty_iff.mp h] }, { simp [←not_nonempty_iff_eq_empty, prod_nonempty_iff.mp h, measurable_set_prod_of_nonempty h] } end lemma measurable_set_swap_iff {s : set (α × β)} : measurable_set (prod.swap ⁻¹' s) ↔ measurable_set s := ⟨λ hs, by { convert measurable_swap hs, ext ⟨x, y⟩, refl }, λ hs, measurable_swap hs⟩ lemma measurable_from_prod_encodable [encodable β] [measurable_singleton_class β] {mγ : measurable_space γ} {f : α × β → γ} (hf : ∀ y, measurable (λ x, f (x, y))) : measurable f := begin intros s hs, have : f ⁻¹' s = ⋃ y, ((λ x, f (x, y)) ⁻¹' s) ×ˢ ({y} : set β), { ext1 ⟨x, y⟩, simp [and_assoc, and.left_comm] }, rw this, exact measurable_set.Union (λ y, (hf y hs).prod (measurable_set_singleton y)) end /-- A piecewise function on countably many pieces is measurable if all the data is measurable. -/ @[measurability] lemma measurable.find {m : measurable_space α} {f : ℕ → α → β} {p : ℕ → α → Prop} [∀ n, decidable_pred (p n)] (hf : ∀ n, measurable (f n)) (hp : ∀ n, measurable_set {x | p n x}) (h : ∀ x, ∃ n, p n x) : measurable (λ x, f (nat.find (h x)) x) := begin have : measurable (λ (p : α × ℕ), f p.2 p.1) := measurable_from_prod_encodable (λ n, hf n), exact this.comp (measurable.prod_mk measurable_id (measurable_find h hp)), end /-- Given countably many disjoint measurable sets `t n` and countably many measurable functions `g n`, one can construct a measurable function that coincides with `g n` on `t n`. -/ lemma exists_measurable_piecewise_nat {m : measurable_space α} (t : ℕ → set β) (t_meas : ∀ n, measurable_set (t n)) (t_disj : pairwise (disjoint on t)) (g : ℕ → β → α) (hg : ∀ n, measurable (g n)) : ∃ f : β → α, measurable f ∧ (∀ n x, x ∈ t n → f x = g n x) := begin classical, let p : ℕ → β → Prop := λ n x, x ∈ t n ∪ (⋃ k, t k)ᶜ, have M : ∀ n, measurable_set {x | p n x} := λ n, (t_meas n).union (measurable_set.compl (measurable_set.Union t_meas)), have P : ∀ x, ∃ n, p n x, { assume x, by_cases H : ∀ (i : ℕ), x ∉ t i, { exact ⟨0, or.inr (by simpa only [mem_Inter, compl_Union] using H)⟩ }, { simp only [not_forall, not_not_mem] at H, rcases H with ⟨n, hn⟩, exact ⟨n, or.inl hn⟩ } }, refine ⟨λ x, g (nat.find (P x)) x, measurable.find hg M P, _⟩, assume n x hx, have : x ∈ t (nat.find (P x)), { have B : x ∈ t (nat.find (P x)) ∪ (⋃ k, t k)ᶜ := nat.find_spec (P x), have B' : (∀ (i : ℕ), x ∉ t i) ↔ false, { simp only [iff_false, not_forall, not_not_mem], exact ⟨n, hx⟩ }, simpa only [B', mem_union_eq, mem_Inter, or_false, compl_Union, mem_compl_eq] using B }, congr, by_contra h, exact t_disj n (nat.find (P x)) (ne.symm h) ⟨hx, this⟩ end end prod section pi variables {π : δ → Type*} [measurable_space α] instance measurable_space.pi [m : Π a, measurable_space (π a)] : measurable_space (Π a, π a) := ⨆ a, (m a).comap (λ b, b a) variables [Π a, measurable_space (π a)] [measurable_space γ] lemma measurable_pi_iff {g : α → Π a, π a} : measurable g ↔ ∀ a, measurable (λ x, g x a) := by simp_rw [measurable_iff_comap_le, measurable_space.pi, measurable_space.comap_supr, measurable_space.comap_comp, function.comp, supr_le_iff] @[measurability] lemma measurable_pi_apply (a : δ) : measurable (λ f : Π a, π a, f a) := measurable.of_comap_le $ le_supr _ a @[measurability] lemma measurable.eval {a : δ} {g : α → Π a, π a} (hg : measurable g) : measurable (λ x, g x a) := (measurable_pi_apply a).comp hg @[measurability] lemma measurable_pi_lambda (f : α → Π a, π a) (hf : ∀ a, measurable (λ c, f c a)) : measurable f := measurable_pi_iff.mpr hf /-- The function `update f a : π a → Π a, π a` is always measurable. This doesn't require `f` to be measurable. This should not be confused with the statement that `update f a x` is measurable. -/ @[measurability] lemma measurable_update (f : Π (a : δ), π a) {a : δ} [decidable_eq δ] : measurable (update f a) := begin apply measurable_pi_lambda, intro x, by_cases hx : x = a, { cases hx, convert measurable_id, ext, simp }, simp_rw [update_noteq hx], apply measurable_const, end /- Even though we cannot use projection notation, we still keep a dot to be consistent with similar lemmas, like `measurable_set.prod`. -/ @[measurability] lemma measurable_set.pi {s : set δ} {t : Π i : δ, set (π i)} (hs : s.countable) (ht : ∀ i ∈ s, measurable_set (t i)) : measurable_set (s.pi t) := by { rw [pi_def], exact measurable_set.bInter hs (λ i hi, measurable_pi_apply _ (ht i hi)) } lemma measurable_set.univ_pi [encodable δ] {t : Π i : δ, set (π i)} (ht : ∀ i, measurable_set (t i)) : measurable_set (pi univ t) := measurable_set.pi (countable_encodable _) (λ i _, ht i) lemma measurable_set_pi_of_nonempty {s : set δ} {t : Π i, set (π i)} (hs : s.countable) (h : (pi s t).nonempty) : measurable_set (pi s t) ↔ ∀ i ∈ s, measurable_set (t i) := begin classical, rcases h with ⟨f, hf⟩, refine ⟨λ hst i hi, _, measurable_set.pi hs⟩, convert measurable_update f hst, rw [update_preimage_pi hi], exact λ j hj _, hf j hj end lemma measurable_set_pi {s : set δ} {t : Π i, set (π i)} (hs : s.countable) : measurable_set (pi s t) ↔ (∀ i ∈ s, measurable_set (t i)) ∨ pi s t = ∅ := begin cases (pi s t).eq_empty_or_nonempty with h h, { simp [h] }, { simp [measurable_set_pi_of_nonempty hs, h, ← not_nonempty_iff_eq_empty] } end section variable (π) @[measurability] lemma measurable_pi_equiv_pi_subtype_prod_symm (p : δ → Prop) [decidable_pred p] : measurable (equiv.pi_equiv_pi_subtype_prod p π).symm := begin apply measurable_pi_iff.2 (λ j, _), by_cases hj : p j, { simp only [hj, dif_pos, equiv.pi_equiv_pi_subtype_prod_symm_apply], have : measurable (λ (f : (Π (i : {x // p x}), π ↑i)), f ⟨j, hj⟩) := measurable_pi_apply ⟨j, hj⟩, exact measurable.comp this measurable_fst }, { simp only [hj, equiv.pi_equiv_pi_subtype_prod_symm_apply, dif_neg, not_false_iff], have : measurable (λ (f : (Π (i : {x // ¬ p x}), π ↑i)), f ⟨j, hj⟩) := measurable_pi_apply ⟨j, hj⟩, exact measurable.comp this measurable_snd } end @[measurability] lemma measurable_pi_equiv_pi_subtype_prod (p : δ → Prop) [decidable_pred p] : measurable (equiv.pi_equiv_pi_subtype_prod p π) := begin refine measurable_prod.2 _, split; { apply measurable_pi_iff.2 (λ j, _), simp only [pi_equiv_pi_subtype_prod_apply, measurable_pi_apply] } end end section fintype local attribute [instance] fintype.to_encodable lemma measurable_set.pi_fintype [fintype δ] {s : set δ} {t : Π i, set (π i)} (ht : ∀ i ∈ s, measurable_set (t i)) : measurable_set (pi s t) := measurable_set.pi (countable_encodable _) ht lemma measurable_set.univ_pi_fintype [fintype δ] {t : Π i, set (π i)} (ht : ∀ i, measurable_set (t i)) : measurable_set (pi univ t) := measurable_set.pi_fintype (λ i _, ht i) end fintype end pi instance tprod.measurable_space (π : δ → Type*) [∀ x, measurable_space (π x)] : ∀ (l : list δ), measurable_space (list.tprod π l) | [] := punit.measurable_space | (i :: is) := @prod.measurable_space _ _ _ (tprod.measurable_space is) section tprod open list variables {π : δ → Type*} [∀ x, measurable_space (π x)] lemma measurable_tprod_mk (l : list δ) : measurable (@tprod.mk δ π l) := begin induction l with i l ih, { exact measurable_const }, { exact (measurable_pi_apply i).prod_mk ih } end lemma measurable_tprod_elim [decidable_eq δ] : ∀ {l : list δ} {i : δ} (hi : i ∈ l), measurable (λ (v : tprod π l), v.elim hi) | (i :: is) j hj := begin by_cases hji : j = i, { subst hji, simp [measurable_fst] }, { rw [funext $ tprod.elim_of_ne _ hji], exact (measurable_tprod_elim (hj.resolve_left hji)).comp measurable_snd } end lemma measurable_tprod_elim' [decidable_eq δ] {l : list δ} (h : ∀ i, i ∈ l) : measurable (tprod.elim' h : tprod π l → Π i, π i) := measurable_pi_lambda _ (λ i, measurable_tprod_elim (h i)) lemma measurable_set.tprod (l : list δ) {s : ∀ i, set (π i)} (hs : ∀ i, measurable_set (s i)) : measurable_set (set.tprod l s) := by { induction l with i l ih, exact measurable_set.univ, exact (hs i).prod ih } end tprod instance {α β} [m₁ : measurable_space α] [m₂ : measurable_space β] : measurable_space (α ⊕ β) := m₁.map sum.inl ⊓ m₂.map sum.inr section sum @[measurability] lemma measurable_inl [measurable_space α] [measurable_space β] : measurable (@sum.inl α β) := measurable.of_le_map inf_le_left @[measurability] lemma measurable_inr [measurable_space α] [measurable_space β] : measurable (@sum.inr α β) := measurable.of_le_map inf_le_right variables {m : measurable_space α} {mβ : measurable_space β} include m mβ lemma measurable_sum {mγ : measurable_space γ} {f : α ⊕ β → γ} (hl : measurable (f ∘ sum.inl)) (hr : measurable (f ∘ sum.inr)) : measurable f := measurable.of_comap_le $ le_inf (measurable_space.comap_le_iff_le_map.2 $ hl) (measurable_space.comap_le_iff_le_map.2 $ hr) @[measurability] lemma measurable.sum_elim {mγ : measurable_space γ} {f : α → γ} {g : β → γ} (hf : measurable f) (hg : measurable g) : measurable (sum.elim f g) := measurable_sum hf hg lemma measurable_set.inl_image {s : set α} (hs : measurable_set s) : measurable_set (sum.inl '' s : set (α ⊕ β)) := ⟨show measurable_set (sum.inl ⁻¹' _), by { rwa [preimage_image_eq], exact (λ a b, sum.inl.inj) }, have sum.inr ⁻¹' (sum.inl '' s : set (α ⊕ β)) = ∅ := eq_empty_of_subset_empty $ assume x ⟨y, hy, eq⟩, by contradiction, show measurable_set (sum.inr ⁻¹' _), by { rw [this], exact measurable_set.empty }⟩ lemma measurable_set_inr_image {s : set β} (hs : measurable_set s) : measurable_set (sum.inr '' s : set (α ⊕ β)) := ⟨ have sum.inl ⁻¹' (sum.inr '' s : set (α ⊕ β)) = ∅ := eq_empty_of_subset_empty $ assume x ⟨y, hy, eq⟩, by contradiction, show measurable_set (sum.inl ⁻¹' _), by { rw [this], exact measurable_set.empty }, show measurable_set (sum.inr ⁻¹' _), by { rwa [preimage_image_eq], exact λ a b, sum.inr.inj }⟩ omit m lemma measurable_set_range_inl [measurable_space α] : measurable_set (range sum.inl : set (α ⊕ β)) := by { rw [← image_univ], exact measurable_set.univ.inl_image } lemma measurable_set_range_inr [measurable_space α] : measurable_set (range sum.inr : set (α ⊕ β)) := by { rw [← image_univ], exact measurable_set_inr_image measurable_set.univ } end sum instance {α} {β : α → Type*} [m : Πa, measurable_space (β a)] : measurable_space (sigma β) := ⨅a, (m a).map (sigma.mk a) end constructions /-- A map `f : α → β` is called a *measurable embedding* if it is injective, measurable, and sends measurable sets to measurable sets. The latter assumption can be replaced with “`f` has measurable inverse `g : range f → α`”, see `measurable_embedding.measurable_range_splitting`, `measurable_embedding.of_measurable_inverse_range`, and `measurable_embedding.of_measurable_inverse`. One more interpretation: `f` is a measurable embedding if it defines a measurable equivalence to its range and the range is a measurable set. One implication is formalized as `measurable_embedding.equiv_range`; the other one follows from `measurable_equiv.measurable_embedding`, `measurable_embedding.subtype_coe`, and `measurable_embedding.comp`. -/ @[protect_proj] structure measurable_embedding {α β : Type*} [measurable_space α] [measurable_space β] (f : α → β) : Prop := (injective : injective f) (measurable : measurable f) (measurable_set_image' : ∀ ⦃s⦄, measurable_set s → measurable_set (f '' s)) namespace measurable_embedding variables {mα : measurable_space α} [measurable_space β] [measurable_space γ] {f : α → β} {g : β → γ} include mα lemma measurable_set_image (hf : measurable_embedding f) {s : set α} : measurable_set (f '' s) ↔ measurable_set s := ⟨λ h, by simpa only [hf.injective.preimage_image] using hf.measurable h, λ h, hf.measurable_set_image' h⟩ lemma id : measurable_embedding (id : α → α) := ⟨injective_id, measurable_id, λ s hs, by rwa image_id⟩ lemma comp (hg : measurable_embedding g) (hf : measurable_embedding f) : measurable_embedding (g ∘ f) := ⟨hg.injective.comp hf.injective, hg.measurable.comp hf.measurable, λ s hs, by rwa [← image_image, hg.measurable_set_image, hf.measurable_set_image]⟩ lemma subtype_coe {s : set α} (hs : measurable_set s) : measurable_embedding (coe : s → α) := { injective := subtype.coe_injective, measurable := measurable_subtype_coe, measurable_set_image' := λ _, measurable_set.subtype_image hs } lemma measurable_set_range (hf : measurable_embedding f) : measurable_set (range f) := by { rw ← image_univ, exact hf.measurable_set_image' measurable_set.univ } lemma measurable_set_preimage (hf : measurable_embedding f) {s : set β} : measurable_set (f ⁻¹' s) ↔ measurable_set (s ∩ range f) := by rw [← image_preimage_eq_inter_range, hf.measurable_set_image] lemma measurable_range_splitting (hf : measurable_embedding f) : measurable (range_splitting f) := λ s hs, by rwa [preimage_range_splitting hf.injective, ← (subtype_coe hf.measurable_set_range).measurable_set_image, ← image_comp, coe_comp_range_factorization, hf.measurable_set_image] lemma measurable_extend (hf : measurable_embedding f) {g : α → γ} {g' : β → γ} (hg : measurable g) (hg' : measurable g') : measurable (extend f g g') := begin refine measurable_of_restrict_of_restrict_compl hf.measurable_set_range _ _, { rw restrict_extend_range, simpa only [range_splitting] using hg.comp hf.measurable_range_splitting }, { rw restrict_extend_compl_range, exact hg'.comp measurable_subtype_coe } end lemma exists_measurable_extend (hf : measurable_embedding f) {g : α → γ} (hg : measurable g) (hne : β → nonempty γ) : ∃ g' : β → γ, measurable g' ∧ g' ∘ f = g := ⟨extend f g (λ x, classical.choice (hne x)), hf.measurable_extend hg (measurable_const' $ λ _ _, rfl), funext $ λ x, extend_apply hf.injective _ _ _⟩ lemma measurable_comp_iff (hg : measurable_embedding g) : measurable (g ∘ f) ↔ measurable f := begin refine ⟨λ H, _, hg.measurable.comp⟩, suffices : measurable ((range_splitting g ∘ range_factorization g) ∘ f), by rwa [(right_inverse_range_splitting hg.injective).comp_eq_id] at this, exact hg.measurable_range_splitting.comp H.subtype_mk end end measurable_embedding lemma measurable_set.exists_measurable_proj {m : measurable_space α} {s : set α} (hs : measurable_set s) (hne : s.nonempty) : ∃ f : α → s, measurable f ∧ ∀ x : s, f x = x := let ⟨f, hfm, hf⟩ := (measurable_embedding.subtype_coe hs).exists_measurable_extend measurable_id (λ _, hne.to_subtype) in ⟨f, hfm, congr_fun hf⟩ /-- Equivalences between measurable spaces. Main application is the simplification of measurability statements along measurable equivalences. -/ structure measurable_equiv (α β : Type*) [measurable_space α] [measurable_space β] extends α ≃ β := (measurable_to_fun : measurable to_equiv) (measurable_inv_fun : measurable to_equiv.symm) infix ` ≃ᵐ `:25 := measurable_equiv namespace measurable_equiv variables (α β) [measurable_space α] [measurable_space β] [measurable_space γ] [measurable_space δ] instance : has_coe_to_fun (α ≃ᵐ β) (λ _, α → β) := ⟨λ e, e.to_fun⟩ variables {α β} @[simp] lemma coe_to_equiv (e : α ≃ᵐ β) : (e.to_equiv : α → β) = e := rfl @[measurability] protected lemma measurable (e : α ≃ᵐ β) : measurable (e : α → β) := e.measurable_to_fun @[simp] lemma coe_mk (e : α ≃ β) (h1 : measurable e) (h2 : measurable e.symm) : ((⟨e, h1, h2⟩ : α ≃ᵐ β) : α → β) = e := rfl /-- Any measurable space is equivalent to itself. -/ def refl (α : Type*) [measurable_space α] : α ≃ᵐ α := { to_equiv := equiv.refl α, measurable_to_fun := measurable_id, measurable_inv_fun := measurable_id } instance : inhabited (α ≃ᵐ α) := ⟨refl α⟩ /-- The composition of equivalences between measurable spaces. -/ def trans (ab : α ≃ᵐ β) (bc : β ≃ᵐ γ) : α ≃ᵐ γ := { to_equiv := ab.to_equiv.trans bc.to_equiv, measurable_to_fun := bc.measurable_to_fun.comp ab.measurable_to_fun, measurable_inv_fun := ab.measurable_inv_fun.comp bc.measurable_inv_fun } /-- The inverse of an equivalence between measurable spaces. -/ def symm (ab : α ≃ᵐ β) : β ≃ᵐ α := { to_equiv := ab.to_equiv.symm, measurable_to_fun := ab.measurable_inv_fun, measurable_inv_fun := ab.measurable_to_fun } @[simp] lemma coe_to_equiv_symm (e : α ≃ᵐ β) : (e.to_equiv.symm : β → α) = e.symm := rfl /-- 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 measurable_equiv (to_equiv_to_fun → apply, to_equiv_inv_fun → symm_apply) lemma to_equiv_injective : injective (to_equiv : (α ≃ᵐ β) → (α ≃ β)) := by { rintro ⟨e₁, _, _⟩ ⟨e₂, _, _⟩ (rfl : e₁ = e₂), refl } @[ext] lemma ext {e₁ e₂ : α ≃ᵐ β} (h : (e₁ : α → β) = e₂) : e₁ = e₂ := to_equiv_injective $ equiv.coe_fn_injective h @[simp] lemma symm_mk (e : α ≃ β) (h1 : measurable e) (h2 : measurable e.symm) : (⟨e, h1, h2⟩ : α ≃ᵐ β).symm = ⟨e.symm, h2, h1⟩ := rfl attribute [simps apply to_equiv] trans refl @[simp] lemma symm_refl (α : Type*) [measurable_space α] : (refl α).symm = refl α := rfl @[simp] theorem symm_comp_self (e : α ≃ᵐ β) : e.symm ∘ e = id := funext e.left_inv @[simp] theorem self_comp_symm (e : α ≃ᵐ β) : e ∘ e.symm = id := funext e.right_inv @[simp] theorem apply_symm_apply (e : α ≃ᵐ β) (y : β) : e (e.symm y) = y := e.right_inv y @[simp] theorem symm_apply_apply (e : α ≃ᵐ β) (x : α) : e.symm (e x) = x := e.left_inv x @[simp] theorem symm_trans_self (e : α ≃ᵐ β) : e.symm.trans e = refl β := ext e.self_comp_symm @[simp] theorem self_trans_symm (e : α ≃ᵐ β) : e.trans e.symm = refl α := ext e.symm_comp_self protected theorem surjective (e : α ≃ᵐ β) : surjective e := e.to_equiv.surjective protected theorem bijective (e : α ≃ᵐ β) : bijective e := e.to_equiv.bijective protected theorem injective (e : α ≃ᵐ β) : injective e := e.to_equiv.injective @[simp] theorem symm_preimage_preimage (e : α ≃ᵐ β) (s : set β) : e.symm ⁻¹' (e ⁻¹' s) = s := e.to_equiv.symm_preimage_preimage s theorem image_eq_preimage (e : α ≃ᵐ β) (s : set α) : e '' s = e.symm ⁻¹' s := e.to_equiv.image_eq_preimage s @[simp] theorem measurable_set_preimage (e : α ≃ᵐ β) {s : set β} : measurable_set (e ⁻¹' s) ↔ measurable_set s := ⟨λ h, by simpa only [symm_preimage_preimage] using e.symm.measurable h, λ h, e.measurable h⟩ @[simp] theorem measurable_set_image (e : α ≃ᵐ β) {s : set α} : measurable_set (e '' s) ↔ measurable_set s := by rw [image_eq_preimage, measurable_set_preimage] /-- A measurable equivalence is a measurable embedding. -/ protected lemma measurable_embedding (e : α ≃ᵐ β) : measurable_embedding e := { injective := e.injective, measurable := e.measurable, measurable_set_image' := λ s, e.measurable_set_image.2 } /-- Equal measurable spaces are equivalent. -/ protected def cast {α β} [i₁ : measurable_space α] [i₂ : measurable_space β] (h : α = β) (hi : i₁ == i₂) : α ≃ᵐ β := { to_equiv := equiv.cast h, measurable_to_fun := by { substI h, substI hi, exact measurable_id }, measurable_inv_fun := by { substI h, substI hi, exact measurable_id }} protected lemma measurable_comp_iff {f : β → γ} (e : α ≃ᵐ β) : measurable (f ∘ e) ↔ measurable f := iff.intro (assume hfe, have measurable (f ∘ (e.symm.trans e).to_equiv) := hfe.comp e.symm.measurable, by rwa [coe_to_equiv, symm_trans_self] at this) (λ h, h.comp e.measurable) /-- Any two types with unique elements are measurably equivalent. -/ def of_unique_of_unique (α β : Type*) [measurable_space α] [measurable_space β] [unique α] [unique β] : α ≃ᵐ β := { to_equiv := equiv_of_unique α β, measurable_to_fun := subsingleton.measurable, measurable_inv_fun := subsingleton.measurable } /-- Products of equivalent measurable spaces are equivalent. -/ def prod_congr (ab : α ≃ᵐ β) (cd : γ ≃ᵐ δ) : α × γ ≃ᵐ β × δ := { to_equiv := prod_congr ab.to_equiv cd.to_equiv, measurable_to_fun := (ab.measurable_to_fun.comp measurable_id.fst).prod_mk (cd.measurable_to_fun.comp measurable_id.snd), measurable_inv_fun := (ab.measurable_inv_fun.comp measurable_id.fst).prod_mk (cd.measurable_inv_fun.comp measurable_id.snd) } /-- Products of measurable spaces are symmetric. -/ def prod_comm : α × β ≃ᵐ β × α := { to_equiv := prod_comm α β, measurable_to_fun := measurable_id.snd.prod_mk measurable_id.fst, measurable_inv_fun := measurable_id.snd.prod_mk measurable_id.fst } /-- Products of measurable spaces are associative. -/ def prod_assoc : (α × β) × γ ≃ᵐ α × (β × γ) := { to_equiv := prod_assoc α β γ, measurable_to_fun := measurable_fst.fst.prod_mk $ measurable_fst.snd.prod_mk measurable_snd, measurable_inv_fun := (measurable_fst.prod_mk measurable_snd.fst).prod_mk measurable_snd.snd } /-- Sums of measurable spaces are symmetric. -/ def sum_congr (ab : α ≃ᵐ β) (cd : γ ≃ᵐ δ) : α ⊕ γ ≃ᵐ β ⊕ δ := { to_equiv := sum_congr ab.to_equiv cd.to_equiv, measurable_to_fun := begin cases ab with ab' abm, cases ab', cases cd with cd' cdm, cases cd', refine measurable_sum (measurable_inl.comp abm) (measurable_inr.comp cdm) end, measurable_inv_fun := begin cases ab with ab' _ abm, cases ab', cases cd with cd' _ cdm, cases cd', refine measurable_sum (measurable_inl.comp abm) (measurable_inr.comp cdm) end } /-- `s ×ˢ t ≃ (s × t)` as measurable spaces. -/ def set.prod (s : set α) (t : set β) : ↥(s ×ˢ t) ≃ᵐ s × t := { to_equiv := equiv.set.prod s t, measurable_to_fun := measurable_id.subtype_coe.fst.subtype_mk.prod_mk measurable_id.subtype_coe.snd.subtype_mk, measurable_inv_fun := measurable.subtype_mk $ measurable_id.fst.subtype_coe.prod_mk measurable_id.snd.subtype_coe } /-- `univ α ≃ α` as measurable spaces. -/ def set.univ (α : Type*) [measurable_space α] : (univ : set α) ≃ᵐ α := { to_equiv := equiv.set.univ α, measurable_to_fun := measurable_id.subtype_coe, measurable_inv_fun := measurable_id.subtype_mk } /-- `{a} ≃ unit` as measurable spaces. -/ def set.singleton (a : α) : ({a} : set α) ≃ᵐ unit := { to_equiv := equiv.set.singleton a, measurable_to_fun := measurable_const, measurable_inv_fun := measurable_const } /-- A set is equivalent to its image under a function `f` as measurable spaces, if `f` is an injective measurable function that sends measurable sets to measurable sets. -/ noncomputable def set.image (f : α → β) (s : set α) (hf : injective f) (hfm : measurable f) (hfi : ∀ s, measurable_set s → measurable_set (f '' s)) : s ≃ᵐ (f '' s) := { to_equiv := equiv.set.image f s hf, measurable_to_fun := (hfm.comp measurable_id.subtype_coe).subtype_mk, measurable_inv_fun := begin rintro t ⟨u, hu, rfl⟩, simp [preimage_preimage, set.image_symm_preimage hf], exact measurable_subtype_coe (hfi u hu) end } /-- The domain of `f` is equivalent to its range as measurable spaces, if `f` is an injective measurable function that sends measurable sets to measurable sets. -/ noncomputable def set.range (f : α → β) (hf : injective f) (hfm : measurable f) (hfi : ∀ s, measurable_set s → measurable_set (f '' s)) : α ≃ᵐ (range f) := (measurable_equiv.set.univ _).symm.trans $ (measurable_equiv.set.image f univ hf hfm hfi).trans $ measurable_equiv.cast (by rw image_univ) (by rw image_univ) /-- `α` is equivalent to its image in `α ⊕ β` as measurable spaces. -/ def set.range_inl : (range sum.inl : set (α ⊕ β)) ≃ᵐ α := { to_fun := λ ab, match ab with | ⟨sum.inl a, _⟩ := a | ⟨sum.inr b, p⟩ := have false, by { cases p, contradiction }, this.elim end, inv_fun := λ a, ⟨sum.inl a, a, rfl⟩, left_inv := by { rintro ⟨ab, a, rfl⟩, refl }, right_inv := assume a, rfl, measurable_to_fun := assume s (hs : measurable_set s), begin refine ⟨_, hs.inl_image, set.ext _⟩, rintros ⟨ab, a, rfl⟩, simp [set.range_inl._match_1] end, measurable_inv_fun := measurable.subtype_mk measurable_inl } /-- `β` is equivalent to its image in `α ⊕ β` as measurable spaces. -/ def set.range_inr : (range sum.inr : set (α ⊕ β)) ≃ᵐ β := { to_fun := λ ab, match ab with | ⟨sum.inr b, _⟩ := b | ⟨sum.inl a, p⟩ := have false, by { cases p, contradiction }, this.elim end, inv_fun := λ b, ⟨sum.inr b, b, rfl⟩, left_inv := by { rintro ⟨ab, b, rfl⟩, refl }, right_inv := assume b, rfl, measurable_to_fun := assume s (hs : measurable_set s), begin refine ⟨_, measurable_set_inr_image hs, set.ext _⟩, rintros ⟨ab, b, rfl⟩, simp [set.range_inr._match_1] end, measurable_inv_fun := measurable.subtype_mk measurable_inr } /-- Products distribute over sums (on the right) as measurable spaces. -/ def sum_prod_distrib (α β γ) [measurable_space α] [measurable_space β] [measurable_space γ] : (α ⊕ β) × γ ≃ᵐ (α × γ) ⊕ (β × γ) := { to_equiv := sum_prod_distrib α β γ, measurable_to_fun := begin refine measurable_of_measurable_union_cover (range sum.inl ×ˢ (univ : set γ)) (range sum.inr ×ˢ (univ : set γ)) (measurable_set_range_inl.prod measurable_set.univ) (measurable_set_range_inr.prod measurable_set.univ) (by { rintro ⟨a|b, c⟩; simp [set.prod_eq] }) _ _, { refine (set.prod (range sum.inl) univ).symm.measurable_comp_iff.1 _, refine (prod_congr set.range_inl (set.univ _)).symm.measurable_comp_iff.1 _, dsimp [(∘)], convert measurable_inl, ext ⟨a, c⟩, refl }, { refine (set.prod (range sum.inr) univ).symm.measurable_comp_iff.1 _, refine (prod_congr set.range_inr (set.univ _)).symm.measurable_comp_iff.1 _, dsimp [(∘)], convert measurable_inr, ext ⟨b, c⟩, refl } end, measurable_inv_fun := measurable_sum ((measurable_inl.comp measurable_fst).prod_mk measurable_snd) ((measurable_inr.comp measurable_fst).prod_mk measurable_snd) } /-- Products distribute over sums (on the left) as measurable spaces. -/ def prod_sum_distrib (α β γ) [measurable_space α] [measurable_space β] [measurable_space γ] : α × (β ⊕ γ) ≃ᵐ (α × β) ⊕ (α × γ) := prod_comm.trans $ (sum_prod_distrib _ _ _).trans $ sum_congr prod_comm prod_comm /-- Products distribute over sums as measurable spaces. -/ def sum_prod_sum (α β γ δ) [measurable_space α] [measurable_space β] [measurable_space γ] [measurable_space δ] : (α ⊕ β) × (γ ⊕ δ) ≃ᵐ ((α × γ) ⊕ (α × δ)) ⊕ ((β × γ) ⊕ (β × δ)) := (sum_prod_distrib _ _ _).trans $ sum_congr (prod_sum_distrib _ _ _) (prod_sum_distrib _ _ _) variables {π π' : δ' → Type*} [∀ x, measurable_space (π x)] [∀ x, measurable_space (π' x)] /-- A family of measurable equivalences `Π a, β₁ a ≃ᵐ β₂ a` generates a measurable equivalence between `Π a, β₁ a` and `Π a, β₂ a`. -/ def Pi_congr_right (e : Π a, π a ≃ᵐ π' a) : (Π a, π a) ≃ᵐ (Π a, π' a) := { to_equiv := Pi_congr_right (λ a, (e a).to_equiv), measurable_to_fun := measurable_pi_lambda _ (λ i, (e i).measurable_to_fun.comp (measurable_pi_apply i)), measurable_inv_fun := measurable_pi_lambda _ (λ i, (e i).measurable_inv_fun.comp (measurable_pi_apply i)) } /-- Pi-types are measurably equivalent to iterated products. -/ @[simps {fully_applied := ff}] def pi_measurable_equiv_tprod [decidable_eq δ'] {l : list δ'} (hnd : l.nodup) (h : ∀ i, i ∈ l) : (Π i, π i) ≃ᵐ list.tprod π l := { to_equiv := list.tprod.pi_equiv_tprod hnd h, measurable_to_fun := measurable_tprod_mk l, measurable_inv_fun := measurable_tprod_elim' h } /-- If `α` has a unique term, then the type of function `α → β` is measurably equivalent to `β`. -/ @[simps {fully_applied := ff}] def fun_unique (α β : Type*) [unique α] [measurable_space β] : (α → β) ≃ᵐ β := { to_equiv := equiv.fun_unique α β, measurable_to_fun := measurable_pi_apply _, measurable_inv_fun := measurable_pi_iff.2 $ λ b, measurable_id } /-- The space `Π i : fin 2, α i` is measurably equivalent to `α 0 × α 1`. -/ @[simps {fully_applied := ff}] def pi_fin_two (α : fin 2 → Type*) [∀ i, measurable_space (α i)] : (Π i, α i) ≃ᵐ α 0 × α 1 := { to_equiv := pi_fin_two_equiv α, measurable_to_fun := measurable.prod (measurable_pi_apply _) (measurable_pi_apply _), measurable_inv_fun := measurable_pi_iff.2 $ fin.forall_fin_two.2 ⟨measurable_fst, measurable_snd⟩ } /-- The space `fin 2 → α` is measurably equivalent to `α × α`. -/ @[simps {fully_applied := ff}] def fin_two_arrow : (fin 2 → α) ≃ᵐ α × α := pi_fin_two (λ _, α) /-- Measurable equivalence between `Π j : fin (n + 1), α j` and `α i × Π j : fin n, α (fin.succ_above i j)`. -/ @[simps {fully_applied := ff}] def pi_fin_succ_above_equiv {n : ℕ} (α : fin (n + 1) → Type*) [Π i, measurable_space (α i)] (i : fin (n + 1)) : (Π j, α j) ≃ᵐ α i × (Π j, α (i.succ_above j)) := { to_equiv := pi_fin_succ_above_equiv α i, measurable_to_fun := (measurable_pi_apply i).prod_mk $ measurable_pi_iff.2 $ λ j, measurable_pi_apply _, measurable_inv_fun := by simp [measurable_pi_iff, i.forall_iff_succ_above, measurable_fst, (measurable_pi_apply _).comp measurable_snd] } variable (π) /-- Measurable equivalence between (dependent) functions on a type and pairs of functions on `{i // p i}` and `{i // ¬p i}`. See also `equiv.pi_equiv_pi_subtype_prod`. -/ @[simps {fully_applied := ff}] def pi_equiv_pi_subtype_prod (p : δ' → Prop) [decidable_pred p] : (Π i, π i) ≃ᵐ ((Π i : subtype p, π i) × (Π i : {i // ¬p i}, π i)) := { to_equiv := pi_equiv_pi_subtype_prod p π, measurable_to_fun := measurable_pi_equiv_pi_subtype_prod π p, measurable_inv_fun := measurable_pi_equiv_pi_subtype_prod_symm π p } end measurable_equiv namespace measurable_embedding variables [measurable_space α] [measurable_space β] [measurable_space γ] {f : α → β} /-- A measurable embedding defines a measurable equivalence between its domain and its range. -/ noncomputable def equiv_range (f : α → β) (hf : measurable_embedding f) : α ≃ᵐ range f := { to_equiv := equiv.of_injective f hf.injective, measurable_to_fun := hf.measurable.subtype_mk, measurable_inv_fun := by { rw coe_of_injective_symm, exact hf.measurable_range_splitting } } lemma of_measurable_inverse_on_range {g : range f → α} (hf₁ : measurable f) (hf₂ : measurable_set (range f)) (hg : measurable g) (H : left_inverse g (range_factorization f)) : measurable_embedding f := begin set e : α ≃ᵐ range f := ⟨⟨range_factorization f, g, H, H.right_inverse_of_surjective surjective_onto_range⟩, hf₁.subtype_mk, hg⟩, exact (measurable_embedding.subtype_coe hf₂).comp e.measurable_embedding end lemma of_measurable_inverse {g : β → α} (hf₁ : measurable f) (hf₂ : measurable_set (range f)) (hg : measurable g) (H : left_inverse g f) : measurable_embedding f := of_measurable_inverse_on_range hf₁ hf₂ (hg.comp measurable_subtype_coe) H end measurable_embedding namespace filter variables [measurable_space α] /-- A filter `f` is measurably generates if each `s ∈ f` includes a measurable `t ∈ f`. -/ class is_measurably_generated (f : filter α) : Prop := (exists_measurable_subset : ∀ ⦃s⦄, s ∈ f → ∃ t ∈ f, measurable_set t ∧ t ⊆ s) instance is_measurably_generated_bot : is_measurably_generated (⊥ : filter α) := ⟨λ _ _, ⟨∅, mem_bot, measurable_set.empty, empty_subset _⟩⟩ instance is_measurably_generated_top : is_measurably_generated (⊤ : filter α) := ⟨λ s hs, ⟨univ, univ_mem, measurable_set.univ, λ x _, hs x⟩⟩ lemma eventually.exists_measurable_mem {f : filter α} [is_measurably_generated f] {p : α → Prop} (h : ∀ᶠ x in f, p x) : ∃ s ∈ f, measurable_set s ∧ ∀ x ∈ s, p x := is_measurably_generated.exists_measurable_subset h lemma eventually.exists_measurable_mem_of_small_sets {f : filter α} [is_measurably_generated f] {p : set α → Prop} (h : ∀ᶠ s in f.small_sets, p s) : ∃ s ∈ f, measurable_set s ∧ p s := let ⟨s, hsf, hs⟩ := eventually_small_sets.1 h, ⟨t, htf, htm, hts⟩ := is_measurably_generated.exists_measurable_subset hsf in ⟨t, htf, htm, hs t hts⟩ instance inf_is_measurably_generated (f g : filter α) [is_measurably_generated f] [is_measurably_generated g] : is_measurably_generated (f ⊓ g) := begin refine ⟨_⟩, rintros t ⟨sf, hsf, sg, hsg, rfl⟩, rcases is_measurably_generated.exists_measurable_subset hsf with ⟨s'f, hs'f, hmf, hs'sf⟩, rcases is_measurably_generated.exists_measurable_subset hsg with ⟨s'g, hs'g, hmg, hs'sg⟩, refine ⟨s'f ∩ s'g, inter_mem_inf hs'f hs'g, hmf.inter hmg, _⟩, exact inter_subset_inter hs'sf hs'sg end lemma principal_is_measurably_generated_iff {s : set α} : is_measurably_generated (𝓟 s) ↔ measurable_set s := begin refine ⟨_, λ hs, ⟨λ t ht, ⟨s, mem_principal_self s, hs, ht⟩⟩⟩, rintros ⟨hs⟩, rcases hs (mem_principal_self s) with ⟨t, ht, htm, hts⟩, have : t = s := subset.antisymm hts ht, rwa ← this end alias principal_is_measurably_generated_iff ↔ _ _root_.measurable_set.principal_is_measurably_generated instance infi_is_measurably_generated {f : ι → filter α} [∀ i, is_measurably_generated (f i)] : is_measurably_generated (⨅ i, f i) := begin refine ⟨λ s hs, _⟩, rw [← equiv.plift.surjective.infi_comp, mem_infi] at hs, rcases hs with ⟨t, ht, ⟨V, hVf, rfl⟩⟩, choose U hUf hU using λ i, is_measurably_generated.exists_measurable_subset (hVf i), refine ⟨⋂ i : t, U i, _, _, _⟩, { rw [← equiv.plift.surjective.infi_comp, mem_infi], refine ⟨t, ht, U, hUf, rfl⟩ }, { haveI := ht.countable.to_encodable, exact measurable_set.Inter (λ i, (hU i).1) }, { exact Inter_mono (λ i, (hU i).2) } end end filter /-- We say that a collection of sets is countably spanning if a countable subset spans the whole type. This is a useful condition in various parts of measure theory. For example, it is a needed condition to show that the product of two collections generate the product sigma algebra, see `generate_from_prod_eq`. -/ def is_countably_spanning (C : set (set α)) : Prop := ∃ (s : ℕ → set α), (∀ n, s n ∈ C) ∧ (⋃ n, s n) = univ lemma is_countably_spanning_measurable_set [measurable_space α] : is_countably_spanning {s : set α | measurable_set s} := ⟨λ _, univ, λ _, measurable_set.univ, Union_const _⟩ namespace measurable_set /-! ### Typeclasses on `subtype measurable_set` -/ variables [measurable_space α] instance : has_mem α (subtype (measurable_set : set α → Prop)) := ⟨λ a s, a ∈ (s : set α)⟩ @[simp] lemma mem_coe (a : α) (s : subtype (measurable_set : set α → Prop)) : a ∈ (s : set α) ↔ a ∈ s := iff.rfl instance : has_emptyc (subtype (measurable_set : set α → Prop)) := ⟨⟨∅, measurable_set.empty⟩⟩ @[simp] lemma coe_empty : ↑(∅ : subtype (measurable_set : set α → Prop)) = (∅ : set α) := rfl instance [measurable_singleton_class α] : has_insert α (subtype (measurable_set : set α → Prop)) := ⟨λ a s, ⟨has_insert.insert a s, s.prop.insert a⟩⟩ @[simp] lemma coe_insert [measurable_singleton_class α] (a : α) (s : subtype (measurable_set : set α → Prop)) : ↑(has_insert.insert a s) = (has_insert.insert a s : set α) := rfl instance : has_compl (subtype (measurable_set : set α → Prop)) := ⟨λ x, ⟨xᶜ, x.prop.compl⟩⟩ @[simp] lemma coe_compl (s : subtype (measurable_set : set α → Prop)) : ↑(sᶜ) = (sᶜ : set α) := rfl instance : has_union (subtype (measurable_set : set α → Prop)) := ⟨λ x y, ⟨x ∪ y, x.prop.union y.prop⟩⟩ @[simp] lemma coe_union (s t : subtype (measurable_set : set α → Prop)) : ↑(s ∪ t) = (s ∪ t : set α) := rfl instance : has_inter (subtype (measurable_set : set α → Prop)) := ⟨λ x y, ⟨x ∩ y, x.prop.inter y.prop⟩⟩ @[simp] lemma coe_inter (s t : subtype (measurable_set : set α → Prop)) : ↑(s ∩ t) = (s ∩ t : set α) := rfl instance : has_sdiff (subtype (measurable_set : set α → Prop)) := ⟨λ x y, ⟨x \ y, x.prop.diff y.prop⟩⟩ @[simp] lemma coe_sdiff (s t : subtype (measurable_set : set α → Prop)) : ↑(s \ t) = (s \ t : set α) := rfl instance : has_bot (subtype (measurable_set : set α → Prop)) := ⟨⟨⊥, measurable_set.empty⟩⟩ @[simp] lemma coe_bot : ↑(⊥ : subtype (measurable_set : set α → Prop)) = (⊥ : set α) := rfl instance : has_top (subtype (measurable_set : set α → Prop)) := ⟨⟨⊤, measurable_set.univ⟩⟩ @[simp] lemma coe_top : ↑(⊤ : subtype (measurable_set : set α → Prop)) = (⊤ : set α) := rfl instance : partial_order (subtype (measurable_set : set α → Prop)) := partial_order.lift _ subtype.coe_injective instance : distrib_lattice (subtype (measurable_set : set α → Prop)) := { sup := (∪), le_sup_left := λ a b, show (a : set α) ≤ a ⊔ b, from le_sup_left, le_sup_right := λ a b, show (b : set α) ≤ a ⊔ b, from le_sup_right, sup_le := λ a b c ha hb, show (a ⊔ b : set α) ≤ c, from sup_le ha hb, inf := (∩), inf_le_left := λ a b, show (a ⊓ b : set α) ≤ a, from inf_le_left, inf_le_right := λ a b, show (a ⊓ b : set α) ≤ b, from inf_le_right, le_inf := λ a b c ha hb, show (a : set α) ≤ b ⊓ c, from le_inf ha hb, le_sup_inf := λ x y z, show ((x ⊔ y) ⊓ (x ⊔ z) : set α) ≤ x ⊔ y ⊓ z, from le_sup_inf, .. measurable_set.subtype.partial_order } instance : bounded_order (subtype (measurable_set : set α → Prop)) := { top := ⊤, le_top := λ a, show (a : set α) ≤ ⊤, from le_top, bot := ⊥, bot_le := λ a, show (⊥ : set α) ≤ a, from bot_le } instance : boolean_algebra (subtype (measurable_set : set α → Prop)) := { sdiff := (\), sup_inf_sdiff := λ a b, subtype.eq $ sup_inf_sdiff a b, inf_inf_sdiff := λ a b, subtype.eq $ inf_inf_sdiff a b, compl := has_compl.compl, inf_compl_le_bot := λ a, boolean_algebra.inf_compl_le_bot (a : set α), top_le_sup_compl := λ a, boolean_algebra.top_le_sup_compl (a : set α), sdiff_eq := λ a b, subtype.eq $ sdiff_eq, .. measurable_set.subtype.bounded_order, .. measurable_set.subtype.distrib_lattice } end measurable_set
73d0c1da75adaa8b31e73089f5ec1231f3e9c5ed
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/Lean3Lib/smt/default_auto.lean
0e78fbd8877475cf77e12e964176e96cc8842a13
[]
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
353
lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Daniel Selsam -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.Lean3Lib.smt.arith import Mathlib.Lean3Lib.smt.array import Mathlib.Lean3Lib.smt.prove namespace Mathlib end Mathlib
25a095f18f574034032a3478566ed7cd7ebab71b
2d787ac9a5ab28a7d164cd13cee8a3cdc1e4680a
/src/my_exercises/00_first_proofs.lean
7e43887d961cb68ce43bf4827caa48909c27a6cd
[ "Apache-2.0" ]
permissive
paulzfm/lean3-tutorials
8c113ec2c9494d401c8a877f094db93e5a631fd6
f41baf1c62c251976ec8dd9ccae9e85ec4c4d336
refs/heads/master
1,679,267,488,532
1,614,782,461,000
1,614,782,461,000
344,157,026
0
0
null
null
null
null
UTF-8
Lean
false
false
18,390
lean
/- This file is intended for Lean beginners. The goal is to demonstrate what it feels like to prove things using Lean and mathlib. Complicated definitions and theory building are not covered. Everything is covered again more slowly and with exercises in the next files. -/ -- We want real numbers and their basic properties import data.real.basic -- We want to be able to use Lean's built-in "help" functionality import tactic.suggest -- We want to be able to define functions using the law of excluded middle noncomputable theory open_locale classical /- Our first goal is to define the set of upper bounds of a set of real numbers. This is already defined in mathlib (in a more general context), but we repeat it for the sake of exposition. Right-click "upper_bounds" below to get offered to jump to mathlib's version -/ #check upper_bounds /-- The set of upper bounds of a set of real numbers ℝ -/ def up_bounds (A : set ℝ) := { x : ℝ | ∀ a ∈ A, a ≤ x } /-- Predicate `is_max a A` means `a` is a maximum of `A` -/ def is_max (a : ℝ) (A : set ℝ) := a ∈ A ∧ a ∈ up_bounds A /- In the above definition, the symbol `∧` means "and". We also see the most visible difference between set theoretic foundations and type theoretic ones (used by almost all proof assistants). In set theory, everything is a set, and the only relation you get from foundations are `=` and `∈`. In type theory, there is a meta-theoretic relation of "typing": `a : ℝ` reads "`a` is a real number" or, more precisely, "the type of `a` is `ℝ`". Here "meta-theoretic" means this is not a statement you can prove or disprove inside the theory, it's a fact that is true or not. Here we impose this fact, in other circumstances, it would be checked by the Lean kernel. By contrast, `a ∈ A` is a statement inside the theory. Here it's part of the definition, in other circumstances it could be something proven inside Lean. -/ /- For illustrative purposes, we now define an infix version of the above predicate. It will allow us to write `a is_a_max_of A`, which is closer to a sentence. -/ infix ` is_a_max_of `:55 := is_max /- Let's prove something now! A set of real numbers has at most one maximum. Here everything left of the final `:` is introducing the objects and assumption. The equality `x = y` right of the colon is the conclusion. -/ lemma unique_max (A : set ℝ) (x y : ℝ) (hx : x is_a_max_of A) (hy : y is_a_max_of A) : x = y := begin -- We first break our assumptions in their two constituent pieces. -- We are free to choose the name following `with` cases hx with x_in x_up, -- destruct hx as [x_in x_up] cases hy with y_in y_up, -- Assumption `x_up` means x isn't less than elements of A, let's apply this to y specialize x_up y, -- x_up y -- Assumption `x_up` now needs the information that `y` is indeed in `A`. specialize x_up y_in, -- apply x_up in y_in -- Let's do this quicker with roles swapped specialize y_up x x_in, -- We explained to Lean the idea of this proof. -- Now we know `x ≤ y` and `y ≤ x`, and Lean shouldn't need more help. -- `linarith` proves equalities and inequalities that follow linearly from -- the assumption we have. linarith, -- lia end /- The above proof is too long, even if you remove comments. We don't really need the unpacking steps at the beginning; we can access both parts of the assumption `hx : x is_a_max_of A` using shortcuts `h.1` and `h.2`. We can also improve readability without assistance from the tactic state display, clearly announcing intermediate goals using `have`. This way we get to the following version of the same proof. -/ example (A : set ℝ) (x y : ℝ) (hx : x is_a_max_of A) (hy : y is_a_max_of A) : x = y := begin -- destruct hx as [hx.1 hx.2]; destruct hy as [hy.1 hy.2] have : x ≤ y, from hy.2 x hx.1, -- have : x ≤ y by exact (hy.2 x hx.1) have : y ≤ x, from hx.2 y hy.1, -- have : y ≤ x by exact (hx.2 y hy.1) linarith, -- lia end /- Notice how mathematics based on type theory treats the assumption `∀ a ∈ A, a ≤ y` as a function turning an element `a` of `A` into the statement `a ≤ y`. More precisely, this assumption is the abbreviation of `∀ a : ℝ, a ∈ A → a ≤ y`. The expression `hy.2 x` appearing in the above proof is then the statement `x ∈ A → x ≤ y`, which itself is a function turning a statement `x ∈ A` into `x ≤ y` so that the full expression `hy.2 x hx.1` is indeed a proof of `x ≤ y`. One could argue a three-line-long proof of this lemma is still two lines too long. This is debatable, but mathlib's style is to write very short proofs for trivial lemmas. Those proofs are not easy to read but they are meant to indicate that the proof is probably not worth reading. In order to reach this stage, we need to know what `linarith` did for us. It invoked the lemma `le_antisymm` which says: `x ≤ y → y ≤ x → x = y`. This arrow, which is used both for function and implication, is right associative. So the statement is `x ≤ y → (y ≤ x → x = y)` which reads: I will send a proof `p` of `x ≤ y` to a function sending a proof `q'` of `y ≤ x` to a proof of `x = y`. Hence `le_antisymm p q'` is a proof of `x = y`. Using this we can get our one-line proof: -/ example (A : set ℝ) (x y : ℝ) (hx : x is_a_max_of A) (hy : y is_a_max_of A) : x = y := le_antisymm (hy.2 x hx.1) (hx.2 y hy.1) /- Such a proof is called a proof term (or a "term mode" proof). Notice it has no `begin` and `end`. It is directly the kind of low level proof that the Lean kernel is consuming. Commands like `cases`, `specialize` or `linarith` are called tactics, they help users constructing proof terms that could be very tedious to write directly. The most efficient proof style combines tactics with proof terms like our previous `have : x ≤ y, from hy.2 x hx.1` where `hy.2 x hx.1` is a proof term embeded inside a tactic mode proof. In the remaining of this file, we'll be characterizing infima of sets of real numbers in term of sequences. -/ /-- The set of lower bounds of a set of real numbers ℝ -/ def low_bounds (A : set ℝ) := { x : ℝ | ∀ a ∈ A, x ≤ a} /- We now define `a` is an infimum of `A`. Again there is already a more general version in mathlib. -/ def is_inf (x : ℝ) (A : set ℝ) := x is_a_max_of (low_bounds A) infix ` is_an_inf_of `:55 := is_inf /- We need to prove that any number which is greater than the infimum of A is greater than some element of A. -/ lemma inf_lt {A : set ℝ} {x : ℝ} (hx : x is_an_inf_of A) : ∀ y, x < y → ∃ a ∈ A, a < y := begin -- Let `y` be any real number. intro y, -- intros y -- Let's prove the contrapositive contrapose, -- rewrite: (P → Q) ↔ (¬ Q → ¬ P) -- The symbol `¬` means negation. Let's ask Lean to rewrite the goal without negation, -- pushing negation through quantifiers and inequalities push_neg, -- Let's assume the premise, calling the assumption `h` intro h, -- intros h -- `h` is exactly saying `y` is a lower bound of `A` so the second part of -- the infimum assumption `hx` applied to `y` and `h` is exactly what we want. exact hx.2 y h, -- exact (hx.2 y h) end /- In the above proof, the sequence `contrapose, push_neg` is so common that it can be abbreviated to `contrapose!`. With these commands, we enter the gray zone between proof checking and proof finding. Practical computer proof checking crucially needs the computer to handle tedious proof steps. In the next proof, we'll start using `linarith` a bit more seriously, going one step further into automation. Our next real goal is to prove inequalities for limits of sequences. We extract the following lemma: if `y ≤ x + ε` for all positive `ε` then `y ≤ x`. -/ lemma le_of_le_add_eps {x y : ℝ} : (∀ ε > 0, y ≤ x + ε) → y ≤ x := begin -- Let's prove the contrapositive, asking Lean to push negations right away. contrapose!, -- Assume `h : x < y`. intro h, -- We need to find `ε` such that `ε` is positive and `x + ε < y`. -- Let's use `(y-x)/2` use ((y-x)/2), -- exists ((y-x)/2) -- we now have two properties to prove. Let's do both in turn, using `linarith` split, linarith, linarith, end /- Note how `linarith` was used for both sub-goals at the end of the above proof. We could have shortened that using the semi-colon combinator instead of comma, writing `split ; linarith`. Next we will study a compressed version of that proof: -/ example {x y : ℝ} : (∀ ε > 0, y ≤ x + ε) → y ≤ x := begin contrapose!, exact assume h, ⟨(y-x)/2, by linarith, by linarith⟩, end /- The angle brackets `⟨` and `⟩` introduce compound data or proofs. A proof of a `∃ z, P z` statemement is composed of a witness `z₀` and a proof `h` of `P z₀`. The compound is denoted by `⟨z₀, h⟩`. In the example above, the predicate is itself compound, it is a conjunction `P z ∧ Q z`. So the proof term should read `⟨z₀, ⟨h₁, h₂⟩⟩` where `h₁` (resp. `h₂`) is a proof of `P z₀` (resp. `Q z₀`). But these so-called "anonymous constructor" brackets are right-associative, so we can get rid of the nested brackets. The keyword `by` introduces tactic mode inside term mode, it is a shorter version of the `begin`/`end` pair, which is more convenient for single tactic blocks. In this example, `begin` enters tactic mode, `exact` leaves it, `by` re-enters it. Going all the way to a proof term would make the proof much longer, because we crucially use automation with `contrapose!` and `linarith`. We can still get a one-line proof using curly braces to gather several tactic invocations, and the `by` abbreviation instead of `begin`/`end`: -/ example {x y : ℝ} : (∀ ε > 0, y ≤ x + ε) → y ≤ x := by { contrapose!, exact assume h, ⟨(y-x)/2, by linarith, by linarith⟩ } /- One could argue that the above proof is a bit too terse, and we are relying too much on linarith. Let's have more `linarith` calls for smaller steps. For the sake of (tiny) variation, we will also assume the premise and argue by contradiction instead of contraposing. -/ example {x y : ℝ} : (∀ ε > 0, y ≤ x + ε) → y ≤ x := begin intro h, -- Assume the conclusion is false, and call this assumption H. by_contradiction H, -- ex_falso push_neg at H, -- Now let's compute. have key := calc -- Each line must end with a colon followed by a proof term -- We want to specialize our assumption `h` to `ε = (y-x)/2` but this is long to -- type, so let's put a hole `_` that Lean will fill in by comparing the -- statement we want to prove and our proof term with a hole. As usual, -- positivity of `(y-x)/2` is proved by `linarith` y ≤ x + (y-x)/2 : h _ (by linarith) ... = x/2 + y/2 : by ring ... < y : by linarith, -- our key now says `y < y` (notice how the sequence `≤`, `=`, `<` was correctly -- merged into a `<`). Let `linarith` find the desired contradiction now. linarith, -- alternatively, we could have provided the proof term -- `exact lt_irrefl y key` end /- Now we are ready for some analysis. Let's set up notation for absolute value -/ local notation `|`x`|` := abs x /- And let's define convergence of sequences of real numbers (of course there is a much more general definition in mathlib). -/ /-- The sequence `u` tends to `l` -/ def limit (u : ℕ → ℝ) (l : ℝ) := ∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - l| ≤ ε /- In the above definition, `u n` denotes the n-th term of the sequence. We can add parentheses to get `u(n)` but we try to avoid parentheses because they pile up very quickly -/ -- If y ≤ u n for all n and u n goes to x then y ≤ x lemma le_lim {x y : ℝ} {u : ℕ → ℝ} (hu : limit u x) (ineq : ∀ n, y ≤ u n) : y ≤ x := begin -- Let's apply our previous lemma apply le_of_le_add_eps, -- We need to prove y ≤ x + ε for all positive ε. -- Let ε be any positive real intros ε ε_pos, -- we now specialize our limit assumption to this `ε`, and immediately -- fix a `N` as promised by the definition. cases hu ε ε_pos with N HN, -- Now we only need to compute until reaching the conclusion calc y ≤ u N : ineq N ... = x + (u N - x) : by linarith -- We'll need `add_le_add` which says `a ≤ b` and `c ≤ d` implies `a + c ≤ b + d` -- We need a lemma saying `z ≤ |z|`. Because we don't know the name of this lemma, -- let's use `library_search`. Because searching thourgh the library is slow, -- Lean will write what it found in the Lean message window when cursor is on -- that line, so that we can replace it by the lemma. We see `le_abs_self`, which -- says `a ≤ |a|`, exactly what we're looking for. ... ≤ x + |u N - x| : add_le_add (by linarith) (by library_search) ... ≤ x + ε : add_le_add (by linarith) (HN N (by linarith)), end /- The next lemma has been extracted from the main proof in order to discuss numbers. In ordinary maths, we know that ℕ is *not* contained in `ℝ`, whatever the construction of real numbers that we use. For instance a natural number is not an equivalence class of Cauchy sequences. But it's very easy to pretend otherwise. Formal maths requires slightly more care. In the statement below, the "type ascription" `(n + 1 : ℝ)` forces Lean to convert the natural number `n+1` into a real number. The "inclusion" map will be displayed in tactic state as `↑`. There are various lemmas asserting this map is compatible with addition and monotone, but we don't want to bother writing their names. The `norm_cast` tactic is designed to wisely apply those lemmas for us. -/ lemma inv_succ_pos : ∀ n : ℕ, 1/(n+1 : ℝ) > 0 := begin -- Let `n` be any integer intro n, -- Since we don't know the name of the relevant lemma, asserting that the inverse of -- a positive number is positive, let's state that is suffices -- to prove that `n+1`, seen as a real number, is positive, and ask `library_search` suffices : (n + 1 : ℝ) > 0, { library_search }, -- Now we want to reduce to a statement about natural numbers, not real numbers -- coming from natural numbers. norm_cast, -- and then get the usual help from `linarith` linarith, end /- That was a pretty long proof for an obvious fact. And stating it as a lemma feels stupid, so let's find a way to write it on one line in case we want to include it in some other proof without stating a lemma. First the `library_search` call above displays the name of the relevant lemma: `one_div_pos`. We can also replace the `linarith` call on the last line by `library_search` to learn the name of the lemma `nat.succ_pos` asserting that the successor of a natural number is positive. There is also a variant on `norm_cast` that combines it with `exact`. The term mode analogue of `intro` is `λ`. We get down to: -/ example : ∀ n : ℕ, 1/(n+1 : ℝ) > 0 := λ n, one_div_pos.mpr (by exact_mod_cast nat.succ_pos n) /- The next proof uses mostly known things, so we will commment only new aspects. -/ lemma limit_inv_succ : ∀ ε > 0, ∃ N : ℕ, ∀ n ≥ N, 1/(n + 1 : ℝ) ≤ ε := begin intros ε ε_pos, suffices : ∃ N : ℕ, 1/ε ≤ N, { -- Because we didn't provide a name for the above statement, Lean called it `this`. -- Let's fix an `N` that works. cases this with N HN, use N, intros n Hn, -- Now we want to rewrite the goal using lemmas -- `div_le_iff' : 0 < b → (a / b ≤ c ↔ a ≤ b * c)` -- `div_le_iff : 0 < b → (a / b ≤ c ↔ a ≤ c * b)` -- the second one will be rewritten from right to left, as indicated by `←`. -- Lean will create a side goal for the required positivity assumption that -- we don't provide for `div_le_iff'`. rw [div_le_iff', ← div_le_iff ε_pos], -- We want to replace assumption `Hn` by its real counter-part so that -- linarith can find what it needs. replace Hn : (N : ℝ) ≤ n, exact_mod_cast Hn, linarith, -- we are still left with the positivity assumption, but already discussed -- how to prove it in the preceding lemma exact_mod_cast nat.succ_pos n }, -- Now we need to prove that sufficient statement. -- We want to use that `ℝ` is archimedean. So we start typing -- `exact archimedean_` and hit Ctrl-space to see what completion Lean proposes -- the lemma `archimedean_iff_nat_le` sounds promising. We select the left to -- right implication using `.1`. This a generic lemma for fields equiped with -- a linear (ie total) order. We need to provide a proof that `ℝ` is indeed -- archimedean. This is done using the `apply_instance` tactic that will be -- covered elsewhere. exact archimedean_iff_nat_le.1 (by apply_instance) (1/ε), end /- We can now put all pieces together, with almost no new things to explain. -/ lemma inf_seq (A : set ℝ) (x : ℝ) : (x is_an_inf_of A) ↔ (x ∈ low_bounds A ∧ ∃ u : ℕ → ℝ, limit u x ∧ ∀ n, u n ∈ A ) := begin split, { intro h, split, { exact h.1 }, -- On the next line, we don't need to tell Lean to treat `n+1` as a real number because -- we add `x` to it, so Lean knows there is only one way to make sense of this expression. have key : ∀ n : ℕ, ∃ a ∈ A, a < x + 1/(n+1), { intro n, -- we can use the lemma we proved above apply inf_lt h, -- and another one we proved! have : 0 < 1/(n+1 : ℝ), from inv_succ_pos n, linarith }, -- Now we need to use axiom of (countable) choice choose u hu using key, use u, split, { intros ε ε_pos, -- again we use a lemma we proved, specializing it to our fixed `ε`, and fixing a `N` cases limit_inv_succ ε ε_pos with N H, use N, intros n hn, have : x ≤ u n, from h.1 _ (hu n).1, have := calc u n < x + 1/(n + 1) : (hu n).2 ... ≤ x + ε : add_le_add (le_refl x) (H n hn), rw abs_of_nonneg ; linarith }, { intro n, exact (hu n).1 } }, { intro h, -- Assumption `h` is made of nested compound statements. We can use the -- recursive version of `cases` to unpack it in one go. rcases h with ⟨x_min, u, lim, huA⟩, split, exact x_min, intros y y_mino, apply le_lim lim, intro n, exact y_mino (u n) (huA n) }, end
92ed20833e5738c4a931023ba8984ed865f98b37
90bd8c2a52dbaaba588bdab57b155a7ec1532de0
/src/homotopy/loop.lean
f107a5a1af66b0397d8584689436da0671c955ce
[ "Apache-2.0" ]
permissive
shingtaklam1324/alg-top
fd434f1478925a232af45f18f370ee3a22811c54
4c88e28df6f0a329f26eab32bae023789193990e
refs/heads/master
1,689,447,024,947
1,630,073,400,000
1,630,073,400,000
381,528,689
2
0
null
null
null
null
UTF-8
Lean
false
false
868
lean
import path.loop import homotopy.path import homotopy.straight_line /-! # Homotopy of Loops In this file we define what it means for two `loop`s to be homotopic, and show that this is an equivalence relation. This is important for the definition of the fundamental group. -/ noncomputable theory variables {X : Type _} [topological_space X] {x₀ : X} /-- We define homotopy of loops to just be an abbreviation for a homotopy of paths. -/ abbreviation loop_homotopy (l₀ l₁ : loop x₀) := path_homotopy l₀ l₁ /-- Two loops are homotopic if there is a homotopy between them. -/ def loop_homotopic (l₀ l₁ : loop x₀) := nonempty (loop_homotopy l₀ l₁) lemma loop_homotopic.equiv : equivalence (@loop_homotopic _ _ x₀) := path_homotopic.equiv instance loop.setoid : setoid (loop x₀) := { r := loop_homotopic, iseqv := loop_homotopic.equiv }
60743a7f28e7a194b89fb58b43e2297332b8d761
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/run/back_chaining1.lean
95b8cf5da41876283c50bf5a604f0ea18673b90c
[ "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
490
lean
-- Backward chaining with tagged rules constants {P Q R S T U : Prop} (Hpq : P → Q) (Hqr : Q → R) (Hrs : R → S) (Hst : S → T) constants (Huq : U → Q) (Hur : U → R) (Hus : U → S) (Hut : U → T) attribute [intro] Hpq Hqr Hrs Hst attribute [intro] Huq Hur Hus Hut open tactic definition lemma1 (p : P) : Q := by back_chaining definition lemma2 (p : P) : R := by back_chaining definition lemma3 (p : P) : S := by back_chaining definition lemma4 (p : P) : T := by back_chaining
7513927b9c7f778d12a5578ea6b920ca00d3a34e
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/run/1655.lean
0d9355a8bafb4f34c01cb6e83062ed6636c7939b
[ "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
141
lean
inductive test0 : Type → Type | intro : (λ t, t → test0 t) nat inductive test1 : Type → Type | intro : let t := nat in t → test1 t
b11b96b38459425b6cbc52b1fe66a3bc0bbf6cce
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/analysis/complex/real_deriv.lean
c06c96100c8cc4b75fcab70575c8901b00e41da7
[ "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
7,340
lean
/- Copyright (c) Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yourong Zang -/ import analysis.calculus.cont_diff import analysis.complex.conformal import analysis.calculus.conformal.normed_space /-! # Real differentiability of complex-differentiable functions `has_deriv_at.real_of_complex` expresses that, if a function on `ℂ` is differentiable (over `ℂ`), then its restriction to `ℝ` is differentiable over `ℝ`, with derivative the real part of the complex derivative. `differentiable_at.conformal_at` states that a real-differentiable function with a nonvanishing differential from the complex plane into an arbitrary complex-normed space is conformal at a point if it's holomorphic at that point. This is a version of Cauchy-Riemann equations. `conformal_at_iff_differentiable_at_or_differentiable_at_comp_conj` proves that a real-differential function with a nonvanishing differential between the complex plane is conformal at a point if and only if it's holomorphic or antiholomorphic at that point. ## TODO * The classical form of Cauchy-Riemann equations * On a connected open set `u`, a function which is `conformal_at` each point is either holomorphic throughout or antiholomorphic throughout. ## Warning We do NOT require conformal functions to be orientation-preserving in this file. -/ section real_deriv_of_complex /-! ### Differentiability of the restriction to `ℝ` of complex functions -/ open complex variables {e : ℂ → ℂ} {e' : ℂ} {z : ℝ} /-- If a complex function is differentiable at a real point, then the induced real function is also differentiable at this point, with a derivative equal to the real part of the complex derivative. -/ theorem has_strict_deriv_at.real_of_complex (h : has_strict_deriv_at e e' z) : has_strict_deriv_at (λx:ℝ, (e x).re) e'.re z := begin have A : has_strict_fderiv_at (coe : ℝ → ℂ) of_real_clm z := of_real_clm.has_strict_fderiv_at, have B : has_strict_fderiv_at e ((continuous_linear_map.smul_right 1 e' : ℂ →L[ℂ] ℂ).restrict_scalars ℝ) (of_real_clm z) := h.has_strict_fderiv_at.restrict_scalars ℝ, have C : has_strict_fderiv_at re re_clm (e (of_real_clm z)) := re_clm.has_strict_fderiv_at, simpa using (C.comp z (B.comp z A)).has_strict_deriv_at end /-- If a complex function is differentiable at a real point, then the induced real function is also differentiable at this point, with a derivative equal to the real part of the complex derivative. -/ theorem has_deriv_at.real_of_complex (h : has_deriv_at e e' z) : has_deriv_at (λx:ℝ, (e x).re) e'.re z := begin have A : has_fderiv_at (coe : ℝ → ℂ) of_real_clm z := of_real_clm.has_fderiv_at, have B : has_fderiv_at e ((continuous_linear_map.smul_right 1 e' : ℂ →L[ℂ] ℂ).restrict_scalars ℝ) (of_real_clm z) := h.has_fderiv_at.restrict_scalars ℝ, have C : has_fderiv_at re re_clm (e (of_real_clm z)) := re_clm.has_fderiv_at, simpa using (C.comp z (B.comp z A)).has_deriv_at end theorem cont_diff_at.real_of_complex {n : ℕ∞} (h : cont_diff_at ℂ n e z) : cont_diff_at ℝ n (λ x : ℝ, (e x).re) z := begin have A : cont_diff_at ℝ n (coe : ℝ → ℂ) z, from of_real_clm.cont_diff.cont_diff_at, have B : cont_diff_at ℝ n e z := h.restrict_scalars ℝ, have C : cont_diff_at ℝ n re (e z), from re_clm.cont_diff.cont_diff_at, exact C.comp z (B.comp z A) end theorem cont_diff.real_of_complex {n : ℕ∞} (h : cont_diff ℂ n e) : cont_diff ℝ n (λ x : ℝ, (e x).re) := cont_diff_iff_cont_diff_at.2 $ λ x, h.cont_diff_at.real_of_complex variables {E : Type*} [normed_add_comm_group E] [normed_space ℂ E] lemma has_strict_deriv_at.complex_to_real_fderiv' {f : ℂ → E} {x : ℂ} {f' : E} (h : has_strict_deriv_at f f' x) : has_strict_fderiv_at f (re_clm.smul_right f' + I • im_clm.smul_right f') x := by simpa only [complex.restrict_scalars_one_smul_right'] using h.has_strict_fderiv_at.restrict_scalars ℝ lemma has_deriv_at.complex_to_real_fderiv' {f : ℂ → E} {x : ℂ} {f' : E} (h : has_deriv_at f f' x) : has_fderiv_at f (re_clm.smul_right f' + I • im_clm.smul_right f') x := by simpa only [complex.restrict_scalars_one_smul_right'] using h.has_fderiv_at.restrict_scalars ℝ lemma has_deriv_within_at.complex_to_real_fderiv' {f : ℂ → E} {s : set ℂ} {x : ℂ} {f' : E} (h : has_deriv_within_at f f' s x) : has_fderiv_within_at f (re_clm.smul_right f' + I • im_clm.smul_right f') s x := by simpa only [complex.restrict_scalars_one_smul_right'] using h.has_fderiv_within_at.restrict_scalars ℝ lemma has_strict_deriv_at.complex_to_real_fderiv {f : ℂ → ℂ} {f' x : ℂ} (h : has_strict_deriv_at f f' x) : has_strict_fderiv_at f (f' • (1 : ℂ →L[ℝ] ℂ)) x := by simpa only [complex.restrict_scalars_one_smul_right] using h.has_strict_fderiv_at.restrict_scalars ℝ lemma has_deriv_at.complex_to_real_fderiv {f : ℂ → ℂ} {f' x : ℂ} (h : has_deriv_at f f' x) : has_fderiv_at f (f' • (1 : ℂ →L[ℝ] ℂ)) x := by simpa only [complex.restrict_scalars_one_smul_right] using h.has_fderiv_at.restrict_scalars ℝ lemma has_deriv_within_at.complex_to_real_fderiv {f : ℂ → ℂ} {s : set ℂ} {f' x : ℂ} (h : has_deriv_within_at f f' s x) : has_fderiv_within_at f (f' • (1 : ℂ →L[ℝ] ℂ)) s x := by simpa only [complex.restrict_scalars_one_smul_right] using h.has_fderiv_within_at.restrict_scalars ℝ end real_deriv_of_complex section conformality /-! ### Conformality of real-differentiable complex maps -/ open complex continuous_linear_map open_locale complex_conjugate variables {E : Type*} [normed_add_comm_group E] [normed_space ℂ E] {z : ℂ} {f : ℂ → E} /-- A real differentiable function of the complex plane into some complex normed space `E` is conformal at a point `z` if it is holomorphic at that point with a nonvanishing differential. This is a version of the Cauchy-Riemann equations. -/ lemma differentiable_at.conformal_at (h : differentiable_at ℂ f z) (hf' : deriv f z ≠ 0) : conformal_at f z := begin rw [conformal_at_iff_is_conformal_map_fderiv, (h.has_fderiv_at.restrict_scalars ℝ).fderiv], apply is_conformal_map_complex_linear, simpa only [ne.def, ext_ring_iff] end /-- A complex function is conformal if and only if the function is holomorphic or antiholomorphic with a nonvanishing differential. -/ lemma conformal_at_iff_differentiable_at_or_differentiable_at_comp_conj {f : ℂ → ℂ} {z : ℂ} : conformal_at f z ↔ (differentiable_at ℂ f z ∨ differentiable_at ℂ (f ∘ conj) (conj z)) ∧ fderiv ℝ f z ≠ 0 := begin rw conformal_at_iff_is_conformal_map_fderiv, rw is_conformal_map_iff_is_complex_or_conj_linear, apply and_congr_left, intros h, have h_diff := h.imp_symm fderiv_zero_of_not_differentiable_at, apply or_congr, { rw differentiable_at_iff_restrict_scalars ℝ h_diff }, rw ← conj_conj z at h_diff, rw differentiable_at_iff_restrict_scalars ℝ (h_diff.comp _ conj_cle.differentiable_at), refine exists_congr (λ g, rfl.congr _), have : fderiv ℝ conj (conj z) = _ := conj_cle.fderiv, simp [fderiv.comp _ h_diff conj_cle.differentiable_at, this, conj_conj], end end conformality
0e2cf6be1dea7d6eb555b5e48defcd0033e89d98
1446f520c1db37e157b631385707cc28a17a595e
/tests/compiler/closure_bug2.lean
dbd040f16b2e4edb06d5575227abb5d938e77fc6
[ "Apache-2.0" ]
permissive
bdbabiak/lean4
cab06b8a2606d99a168dd279efdd404edb4e825a
3f4d0d78b2ce3ef541cb643bbe21496bd6b057ac
refs/heads/master
1,615,045,275,530
1,583,793,696,000
1,583,793,696,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
553
lean
def f (x : Nat) : Nat × (Nat → String) := let x1 := x + 1; let x2 := x + 2; let x3 := x + 3; let x4 := x + 4; let x5 := x + 5; let x6 := x + 6; let x7 := x + 7; let x8 := x + 8; let x9 := x + 9; let x10 := x + 10; let x11 := x + 11; let x12 := x + 12; let x13 := x + 13; let x14 := x + 14; let x15 := x + 15; let x16 := x + 16; let x17 := x + 17; (x, fun y => toString [x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17]) def main (xs : List String) : IO Unit := IO.println ((f (xs.headD "0").toNat).2 (xs.headD "0").toNat)
88d059181093d09613d57c7bdaaccc420c0549d3
d1a52c3f208fa42c41df8278c3d280f075eb020c
/src/Lean/Util/MonadCache.lean
743bb1f32c8eedf0827f7a1a910c247d1c0ec3de
[ "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
4,767
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 Std.Data.HashMap namespace Lean /-- Interface for caching results. -/ class MonadCache (α β : Type) (m : Type → Type) where findCached? : α → m (Option β) cache : α → β → m Unit /-- If entry `a := b` is already in the cache, then return `b`. Otherwise, execute `b ← f ()`, store `a := b` in the cache and return `b`. -/ @[inline] def checkCache {α β : Type} {m : Type → Type} [MonadCache α β m] [Monad m] (a : α) (f : Unit → m β) : m β := do match (← MonadCache.findCached? a) with | some b => pure b | none => do let b ← f () MonadCache.cache a b pure b instance {α β ρ : Type} {m : Type → Type} [MonadCache α β m] : MonadCache α β (ReaderT ρ m) where findCached? a r := MonadCache.findCached? a cache a b r := MonadCache.cache a b instance {α β ε : Type} {m : Type → Type} [MonadCache α β m] [Monad m] : MonadCache α β (ExceptT ε m) where findCached? a := ExceptT.lift $ MonadCache.findCached? a cache a b := ExceptT.lift $ MonadCache.cache a b open Std (HashMap) /-- Adapter for implementing `MonadCache` interface using `HashMap`s. We just have to specify how to extract/modify the `HashMap`. -/ class MonadHashMapCacheAdapter (α β : Type) (m : Type → Type) [BEq α] [Hashable α] where getCache : m (HashMap α β) modifyCache : (HashMap α β → HashMap α β) → m Unit namespace MonadHashMapCacheAdapter @[inline] def findCached? {α β : Type} {m : Type → Type} [BEq α] [Hashable α] [Monad m] [MonadHashMapCacheAdapter α β m] (a : α) : m (Option β) := do let c ← getCache pure (c.find? a) @[inline] def cache {α β : Type} {m : Type → Type} [BEq α] [Hashable α] [MonadHashMapCacheAdapter α β m] (a : α) (b : β) : m Unit := modifyCache fun s => s.insert a b instance {α β : Type} {m : Type → Type} [BEq α] [Hashable α] [Monad m] [MonadHashMapCacheAdapter α β m] : MonadCache α β m where findCached? := MonadHashMapCacheAdapter.findCached? cache := MonadHashMapCacheAdapter.cache end MonadHashMapCacheAdapter def MonadCacheT {ω} (α β : Type) (m : Type → Type) [STWorld ω m] [BEq α] [Hashable α] := StateRefT (HashMap α β) m namespace MonadCacheT variable {ω α β : Type} {m : Type → Type} [STWorld ω m] [BEq α] [Hashable α] [MonadLiftT (ST ω) m] [Monad m] instance : MonadHashMapCacheAdapter α β (MonadCacheT α β m) where getCache := (get : StateRefT' ..) modifyCache f := (modify f : StateRefT' ..) @[inline] def run {σ} (x : MonadCacheT α β m σ) : m σ := x.run' Std.mkHashMap instance : Monad (MonadCacheT α β m) := inferInstanceAs (Monad (StateRefT' _ _ _)) instance : MonadLift m (MonadCacheT α β m) := inferInstanceAs (MonadLift m (StateRefT' _ _ _)) instance (ε) [MonadExceptOf ε m] : MonadExceptOf ε (MonadCacheT α β m) := inferInstanceAs (MonadExceptOf ε (StateRefT' _ _ _)) instance : MonadControl m (MonadCacheT α β m) := inferInstanceAs (MonadControl m (StateRefT' _ _ _)) instance [MonadFinally m] : MonadFinally (MonadCacheT α β m) := inferInstanceAs (MonadFinally (StateRefT' _ _ _)) instance [MonadRef m] : MonadRef (MonadCacheT α β m) := inferInstanceAs (MonadRef (StateRefT' _ _ _)) instance [Alternative m] : Alternative (MonadCacheT α β m) := inferInstanceAs (Alternative (StateRefT' _ _ _)) end MonadCacheT /- Similar to `MonadCacheT`, but using `StateT` instead of `StateRefT` -/ def MonadStateCacheT (α β : Type) (m : Type → Type) [BEq α] [Hashable α] := StateT (HashMap α β) m namespace MonadStateCacheT variable {ω α β : Type} {m : Type → Type} [STWorld ω m] [BEq α] [Hashable α] [MonadLiftT (ST ω) m] [Monad m] instance : MonadHashMapCacheAdapter α β (MonadStateCacheT α β m) where getCache := (get : StateT ..) modifyCache f := (modify f : StateT ..) @[inline] def run {σ} (x : MonadStateCacheT α β m σ) : m σ := x.run' Std.mkHashMap instance : Monad (MonadStateCacheT α β m) := inferInstanceAs (Monad (StateT _ _)) instance : MonadLift m (MonadStateCacheT α β m) := inferInstanceAs (MonadLift m (StateT _ _)) instance (ε) [MonadExceptOf ε m] : MonadExceptOf ε (MonadStateCacheT α β m) := inferInstanceAs (MonadExceptOf ε (StateT _ _)) instance : MonadControl m (MonadStateCacheT α β m) := inferInstanceAs (MonadControl m (StateT _ _)) instance [MonadFinally m] : MonadFinally (MonadStateCacheT α β m) := inferInstanceAs (MonadFinally (StateT _ _)) instance [MonadRef m] : MonadRef (MonadStateCacheT α β m) := inferInstanceAs (MonadRef (StateT _ _)) end MonadStateCacheT end Lean
90238ff5d6af802fd439f7415fbc7873644deda5
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/run/discrTreeOffset.lean
8447fcdfd2b2b2c84c92f5bc46e1af7df4d9e14b
[ "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
580
lean
def f (x : Nat) (y : Nat) := 3 + x def g (x : Nat) := x*x*x @[simp] theorem eq1 (x y : Nat) : f (x+2) y = x+5 := by simp [f] rw [Nat.add_left_comm] theorem ex1 : g (f (x+3) y) = g (x+6) := by simp theorem ex2 : g (f (x.succ.succ) y) = g (x+5) := by simp theorem ex3 : g (f 3 y) = g 6 := by simp theorem ex4 : g (f 2 y) = g 5 := by simp theorem ex5 : g (f (x.succ.succ.succ) y) = g (x+6) := by simp def h (x : Nat) : Type := match x with | 0 => Nat | _ => Unit @[simp] theorem h_zero : h 0 = Nat := rfl theorem ex6 : h Nat.zero = Nat := by simp
7c4317f194ab2d2636a178ebc00ddcdd2b7ccff8
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/Lean3Lib/data/rbtree/default.lean
62c9a08d11a4e2cd968b0fad46e193b6ac448fe8
[]
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
287
lean
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.Lean3Lib.data.rbtree.main namespace Mathlib
9fb3090d68552b74781db505be7baf2f262b246c
dd0f5513e11c52db157d2fcc8456d9401a6cd9da
/07_Induction_and_Recursion.org.10.lean
96384a701bff54a2fc9b0c9c3546a4b92279f10e
[]
no_license
cjmazey/lean-tutorial
ba559a49f82aa6c5848b9bf17b7389bf7f4ba645
381f61c9fcac56d01d959ae0fa6e376f2c4e3b34
refs/heads/master
1,610,286,098,832
1,447,124,923,000
1,447,124,923,000
43,082,433
0
0
null
null
null
null
UTF-8
Lean
false
false
486
lean
/- page 103 -/ import standard namespace hide -- BEGIN open nat inductive vector (A : Type) : nat → Type := | nil {} : vector A zero | cons : Π {n}, A → vector A n → vector A (succ n) open vector notation h :: t := cons h t check @vector.cases_on -- Π {A : Type} -- {C : Π (a : ℕ), vector A a → Type} -- {a : ℕ} -- (n : vector A a), -- (e1 : C 0 nil) -- (e2 : Π {n : ℕ} (a : A) (a_1 : vector A n), C (succ n) (cons a a_1)), -- C a n -- END end hide
88b1ab7ee8cf64a0ff6d8c0b11621b9d35d5762e
3aad12fe82645d2d3173fbedc2e5c2ba945a4d75
/src/category/monad_trans.lean
0c741270dab576f5f023ef07451b040f4375f55d
[]
no_license
seanpm2001/LeanProver-Community_MathLIB-Nursery
4f88d539cb18d73a94af983092896b851e6640b5
0479b31fa5b4d39f41e89b8584c9f5bf5271e8ec
refs/heads/master
1,688,730,786,645
1,572,070,026,000
1,572,070,026,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
4,318
lean
import tactic universes u v w class is_lawful_monad_lift (m : Type u → Type v) (n : Type u → Type w) [has_monad_lift m n] [monad m] [monad n] := (monad_lift_pure : ∀ {α} (x : α), has_monad_lift.monad_lift (pure x : m α) = (pure x : n α)) (monad_lift_bind : ∀ {α β} (x : m α) (f : α → m β), (has_monad_lift.monad_lift $ x >>= f : n β) = has_monad_lift.monad_lift x >>= has_monad_lift.monad_lift ∘ f ) class is_lawful_monad_lift_t (m : Type u → Type v) (n : Type u → Type w) [has_monad_lift_t m n] [monad m] [monad n] := (monad_lift_pure : ∀ {α} (x : α), has_monad_lift_t.monad_lift (pure x : m α) = (pure x : n α)) (monad_lift_bind : ∀ {α β} (x : m α) (f : α → m β), (has_monad_lift_t.monad_lift $ x >>= f : n β) = has_monad_lift_t.monad_lift x >>= has_monad_lift_t.monad_lift ∘ f ) lemma is_lawful_monad_lift_t.monad_lift_and_then (m : Type u → Type v) (n : Type u → Type w) [has_monad_lift_t m n] [monad m] [monad n] [is_lawful_monad_lift_t m n] {α β} (x : m α) (f : m β) : (has_monad_lift_t.monad_lift $ x >> f : n β) = has_monad_lift_t.monad_lift x >> has_monad_lift_t.monad_lift f := by { simp [(>>),is_lawful_monad_lift_t.monad_lift_bind n] } export is_lawful_monad_lift_t (monad_lift_pure monad_lift_bind monad_lift_and_then) instance has_lawful_monad_lift_t_trans (m n o) [monad m] [monad n] [monad o] [has_monad_lift n o] [has_monad_lift_t m n] [is_lawful_monad_lift n o] [is_lawful_monad_lift_t m n] : is_lawful_monad_lift_t m o := by constructor; intros; simp [monad_lift]; [ simp [monad_lift_pure m n,is_lawful_monad_lift.monad_lift_pure n o], simp [monad_lift_bind n,is_lawful_monad_lift.monad_lift_bind o] ] instance has_lawful_monad_lift_t_refl (m) [monad m] : is_lawful_monad_lift_t m m := by constructor; intros; simp [monad_lift] class is_lawful_monad_state (σ : out_param (Type u)) (m : Type u → Type v) [monad m] [monad_state σ m] := (lift_pure : ∀ {α} (x : α), monad_state.lift (pure x : state σ α) = (pure x : m α)) (lift_bind : ∀ {α β} (x : state σ α) (f : α → state σ β), (monad_state.lift $ x >>= f : m β) = monad_state.lift x >>= monad_state.lift ∘ f ) (lift_put : ∀ (x : σ), monad_state.lift (put x : state σ punit) = (put x : m punit)) (lift_get : monad_state.lift (get : state σ σ) = (get : m σ)) open is_lawful_monad_state lemma is_lawful_monad_state.lift_and_then {m} [monad m] {α β σ} [monad_state σ m] [is_lawful_monad_state σ m] (x : state σ α) (f : state σ β) : (monad_state.lift $ x >> f : m β) = monad_state.lift x >> monad_state.lift f := by { simp [(>>),lift_bind m] } instance (σ : (Type u)) (m : Type u → Type v) [monad m] [is_lawful_monad m] : is_lawful_monad_state σ (state_t σ m) := by { constructor; intros; try { refl }, { simp [(>>=),state_t.bind,monad_state.lift,id_bind], congr, ext z, cases x.run z, refl }, } instance (σ σ' : (Type u)) (m : Type u → Type v) [monad m] [is_lawful_monad m] [monad_state σ m] [is_lawful_monad_state σ m] : is_lawful_monad_state σ (reader_t σ' m) := by { constructor; intros; simp [monad_state.lift,lift_pure m,lift_bind m]; refl } instance (σ : (Type u)) (m : Type u → Type v) [monad m] [is_lawful_monad m] : is_lawful_monad_lift m (state_t σ m) := by { constructor; intros; try { refl }, all_goals { simp [(>>=),state_t.bind,state_t.lift,has_monad_lift.monad_lift,id_bind,bind_assoc]; refl }, } instance (σ : (Type u)) (m : Type u → Type v) [monad m] : is_lawful_monad_lift m (reader_t σ m) := by { constructor; intros; refl } -- class is_lawful_monad_reader (σ : out_param (Type u)) (m : Type u → Type v) [monad m] [monad_reader σ m] := -- (lift_pure {} : ∀ {α} (x : α), -- monad_reader.lift (pure x : reader σ α) = (pure x : m α)) -- (lift_bind {} : ∀ {α β} (x : state σ α) (f : α → state σ β), -- (monad_state.lift $ x >>= f : m β) = -- monad_state.lift x >>= monad_state.lift ∘ f ) -- instance (σ : (Type u)) (m : Type u → Type v) [monad m] [is_lawful_monad m] : is_lawful_monad_state σ (state_t σ m) := -- by { constructor; intros, -- { refl }, -- { simp [(>>=),state_t.bind,monad_state.lift,id_bind], -- congr, ext z, cases x.run z, refl } } -- class is_lawful_monad_state
afec36cd7bdb89554edf5dd62600bbe745bb6291
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/src/Init/Data/Prod.lean
fd1b3814cf80d76d2658d1d1518e60c55bf5a3a6
[ "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
485
lean
/- Copyright (c) 2022 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura -/ prelude import Init.SimpLemmas instance [BEq α] [BEq β] [LawfulBEq α] [LawfulBEq β] : LawfulBEq (α × β) where eq_of_beq {a b} (h : a.1 == b.1 && a.2 == b.2) := by cases a; cases b refine congr (congrArg _ (eq_of_beq ?_)) (eq_of_beq ?_) <;> simp_all rfl {a} := by cases a; simp [BEq.beq, LawfulBEq.rfl]
03cf3e280a2b7d46fd69ea1c96ef417d65d6f34b
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
/src/data/equiv/ring.lean
426f73aba43b0f13f7059659919f2fe73af8afc7
[ "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
15,926
lean
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Callum Sutton, Yury Kudryashov -/ import data.equiv.mul_add import algebra.field import algebra.opposites import algebra.big_operators.basic /-! # (Semi)ring equivs In this file we define extension of `equiv` called `ring_equiv`, which is a datatype representing an isomorphism of `semiring`s, `ring`s, `division_ring`s, or `field`s. We also introduce the corresponding group of automorphisms `ring_aut`. ## Notations * ``infix ` ≃+* `:25 := ring_equiv`` The extended equiv have coercions to functions, and the coercion is the canonical notation when treating the isomorphism as maps. ## Implementation notes The fields for `ring_equiv` now avoid the unbundled `is_mul_hom` and `is_add_hom`, as these are deprecated. Definition of multiplication in the groups of automorphisms agrees with function composition, multiplication in `equiv.perm`, and multiplication in `category_theory.End`, not with `category_theory.comp`. ## Tags equiv, mul_equiv, add_equiv, ring_equiv, mul_aut, add_aut, ring_aut -/ open_locale big_operators variables {R : Type*} {S : Type*} {S' : Type*} set_option old_structure_cmd true /-- An equivalence between two (semi)rings that preserves the algebraic structure. -/ structure ring_equiv (R S : Type*) [has_mul R] [has_add R] [has_mul S] [has_add S] extends R ≃ S, R ≃* S, R ≃+ S infix ` ≃+* `:25 := ring_equiv /-- The "plain" equivalence of types underlying an equivalence of (semi)rings. -/ add_decl_doc ring_equiv.to_equiv /-- The equivalence of additive monoids underlying an equivalence of (semi)rings. -/ add_decl_doc ring_equiv.to_add_equiv /-- The equivalence of multiplicative monoids underlying an equivalence of (semi)rings. -/ add_decl_doc ring_equiv.to_mul_equiv namespace ring_equiv section basic variables [has_mul R] [has_add R] [has_mul S] [has_add S] [has_mul S'] [has_add S'] instance : has_coe_to_fun (R ≃+* S) (λ _, R → S) := ⟨ring_equiv.to_fun⟩ @[simp] lemma to_fun_eq_coe (f : R ≃+* S) : f.to_fun = f := rfl /-- A ring isomorphism preserves multiplication. -/ @[simp] lemma map_mul (e : R ≃+* S) (x y : R) : e (x * y) = e x * e y := e.map_mul' x y /-- A ring isomorphism preserves addition. -/ @[simp] lemma map_add (e : R ≃+* S) (x y : R) : e (x + y) = e x + e y := e.map_add' x y /-- Two ring isomorphisms agree if they are defined by the same underlying function. -/ @[ext] lemma ext {f g : R ≃+* S} (h : ∀ x, f x = g x) : f = g := begin have h₁ : f.to_equiv = g.to_equiv := equiv.ext h, cases f, cases g, congr, { exact (funext h) }, { exact congr_arg equiv.inv_fun h₁ } end @[simp] theorem coe_mk (e e' h₁ h₂ h₃ h₄) : ⇑(⟨e, e', h₁, h₂, h₃, h₄⟩ : R ≃+* S) = e := rfl @[simp] theorem mk_coe (e : R ≃+* S) (e' h₁ h₂ h₃ h₄) : (⟨e, e', h₁, h₂, h₃, h₄⟩ : R ≃+* S) = e := ext $ λ _, rfl protected lemma congr_arg {f : R ≃+* S} : Π {x x' : R}, x = x' → f x = f x' | _ _ rfl := rfl protected lemma congr_fun {f g : R ≃+* S} (h : f = g) (x : R) : f x = g x := h ▸ rfl lemma ext_iff {f g : R ≃+* S} : f = g ↔ ∀ x, f x = g x := ⟨λ h x, h ▸ rfl, ext⟩ instance has_coe_to_mul_equiv : has_coe (R ≃+* S) (R ≃* S) := ⟨ring_equiv.to_mul_equiv⟩ instance has_coe_to_add_equiv : has_coe (R ≃+* S) (R ≃+ S) := ⟨ring_equiv.to_add_equiv⟩ lemma to_add_equiv_eq_coe (f : R ≃+* S) : f.to_add_equiv = ↑f := rfl lemma to_mul_equiv_eq_coe (f : R ≃+* S) : f.to_mul_equiv = ↑f := rfl @[simp, norm_cast] lemma coe_to_mul_equiv (f : R ≃+* S) : ⇑(f : R ≃* S) = f := rfl @[simp, norm_cast] lemma coe_to_add_equiv (f : R ≃+* S) : ⇑(f : R ≃+ S) = f := rfl /-- The `ring_equiv` between two semirings with a unique element. -/ def ring_equiv_of_unique_of_unique {M N} [unique M] [unique N] [has_add M] [has_mul M] [has_add N] [has_mul N] : M ≃+* N := { ..add_equiv.add_equiv_of_unique_of_unique, ..mul_equiv.mul_equiv_of_unique_of_unique} instance {M N} [unique M] [unique N] [has_add M] [has_mul M] [has_add N] [has_mul N] : unique (M ≃+* N) := { default := ring_equiv_of_unique_of_unique, uniq := λ _, ext $ λ x, subsingleton.elim _ _ } variable (R) /-- The identity map is a ring isomorphism. -/ @[refl] protected def refl : R ≃+* R := { .. mul_equiv.refl R, .. add_equiv.refl R } @[simp] lemma refl_apply (x : R) : ring_equiv.refl R x = x := rfl @[simp] lemma coe_add_equiv_refl : (ring_equiv.refl R : R ≃+ R) = add_equiv.refl R := rfl @[simp] lemma coe_mul_equiv_refl : (ring_equiv.refl R : R ≃* R) = mul_equiv.refl R := rfl instance : inhabited (R ≃+* R) := ⟨ring_equiv.refl R⟩ variables {R} /-- The inverse of a ring isomorphism is a ring isomorphism. -/ @[symm] protected def symm (e : R ≃+* S) : S ≃+* R := { .. e.to_mul_equiv.symm, .. e.to_add_equiv.symm } /-- See Note [custom simps projection] -/ def simps.symm_apply (e : R ≃+* S) : S → R := e.symm initialize_simps_projections ring_equiv (to_fun → apply, inv_fun → symm_apply) @[simp] lemma symm_symm (e : R ≃+* S) : e.symm.symm = e := ext $ λ x, rfl lemma symm_bijective : function.bijective (ring_equiv.symm : (R ≃+* S) → (S ≃+* R)) := equiv.bijective ⟨ring_equiv.symm, ring_equiv.symm, symm_symm, symm_symm⟩ @[simp] lemma mk_coe' (e : R ≃+* S) (f h₁ h₂ h₃ h₄) : (ring_equiv.mk f ⇑e h₁ h₂ h₃ h₄ : S ≃+* R) = e.symm := symm_bijective.injective $ ext $ λ x, rfl @[simp] lemma symm_mk (f : R → S) (g h₁ h₂ h₃ h₄) : (mk f g h₁ h₂ h₃ h₄).symm = { to_fun := g, inv_fun := f, ..(mk f g h₁ h₂ h₃ h₄).symm} := rfl /-- Transitivity of `ring_equiv`. -/ @[trans] protected def trans (e₁ : R ≃+* S) (e₂ : S ≃+* S') : R ≃+* S' := { .. (e₁.to_mul_equiv.trans e₂.to_mul_equiv), .. (e₁.to_add_equiv.trans e₂.to_add_equiv) } @[simp] lemma trans_apply (e₁ : R ≃+* S) (e₂ : S ≃+* S') (a : R) : e₁.trans e₂ a = e₂ (e₁ a) := rfl protected lemma bijective (e : R ≃+* S) : function.bijective e := e.to_equiv.bijective protected lemma injective (e : R ≃+* S) : function.injective e := e.to_equiv.injective protected lemma surjective (e : R ≃+* S) : function.surjective e := e.to_equiv.surjective @[simp] lemma apply_symm_apply (e : R ≃+* S) : ∀ x, e (e.symm x) = x := e.to_equiv.apply_symm_apply @[simp] lemma symm_apply_apply (e : R ≃+* S) : ∀ x, e.symm (e x) = x := e.to_equiv.symm_apply_apply lemma image_eq_preimage (e : R ≃+* S) (s : set R) : e '' s = e.symm ⁻¹' s := e.to_equiv.image_eq_preimage s end basic section opposite open opposite /-- A ring iso `α ≃+* β` can equivalently be viewed as a ring iso `αᵒᵖ ≃+* βᵒᵖ`. -/ @[simps] protected def op {α β} [has_add α] [has_mul α] [has_add β] [has_mul β] : (α ≃+* β) ≃ (αᵒᵖ ≃+* βᵒᵖ) := { to_fun := λ f, { ..f.to_add_equiv.op, ..f.to_mul_equiv.op}, inv_fun := λ f, { ..(add_equiv.op.symm f.to_add_equiv), ..(mul_equiv.op.symm f.to_mul_equiv) }, left_inv := λ f, by { ext, refl }, right_inv := λ f, by { ext, refl } } /-- The 'unopposite' of a ring iso `αᵒᵖ ≃+* βᵒᵖ`. Inverse to `ring_equiv.op`. -/ @[simp] protected def unop {α β} [has_add α] [has_mul α] [has_add β] [has_mul β] : (αᵒᵖ ≃+* βᵒᵖ) ≃ (α ≃+* β) := ring_equiv.op.symm section comm_semiring variables (R) [comm_semiring R] /-- A commutative ring is isomorphic to its opposite. -/ def to_opposite : R ≃+* Rᵒᵖ := { map_add' := λ x y, rfl, map_mul' := λ x y, mul_comm (op y) (op x), ..equiv_to_opposite } @[simp] lemma to_opposite_apply (r : R) : to_opposite R r = op r := rfl @[simp] lemma to_opposite_symm_apply (r : Rᵒᵖ) : (to_opposite R).symm r = unop r := rfl end comm_semiring end opposite section non_unital_semiring variables [non_unital_non_assoc_semiring R] [non_unital_non_assoc_semiring S] (f : R ≃+* S) (x y : R) /-- A ring isomorphism sends zero to zero. -/ @[simp] lemma map_zero : f 0 = 0 := (f : R ≃+ S).map_zero variable {x} @[simp] lemma map_eq_zero_iff : f x = 0 ↔ x = 0 := (f : R ≃+ S).map_eq_zero_iff lemma map_ne_zero_iff : f x ≠ 0 ↔ x ≠ 0 := (f : R ≃+ S).map_ne_zero_iff end non_unital_semiring section semiring variables [non_assoc_semiring R] [non_assoc_semiring S] (f : R ≃+* S) (x y : R) /-- A ring isomorphism sends one to one. -/ @[simp] lemma map_one : f 1 = 1 := (f : R ≃* S).map_one variable {x} @[simp] lemma map_eq_one_iff : f x = 1 ↔ x = 1 := (f : R ≃* S).map_eq_one_iff lemma map_ne_one_iff : f x ≠ 1 ↔ x ≠ 1 := (f : R ≃* S).map_ne_one_iff /-- Produce a ring isomorphism from a bijective ring homomorphism. -/ noncomputable def of_bijective (f : R →+* S) (hf : function.bijective f) : R ≃+* S := { .. equiv.of_bijective f hf, .. f } @[simp] lemma coe_of_bijective (f : R →+* S) (hf : function.bijective f) : (of_bijective f hf : R → S) = f := rfl lemma of_bijective_apply (f : R →+* S) (hf : function.bijective f) (x : R) : of_bijective f hf x = f x := rfl end semiring section variables [ring R] [ring S] (f : R ≃+* S) (x y : R) @[simp] lemma map_neg : f (-x) = -f x := (f : R ≃+ S).map_neg x @[simp] lemma map_sub : f (x - y) = f x - f y := (f : R ≃+ S).map_sub x y @[simp] lemma map_neg_one : f (-1) = -1 := f.map_one ▸ f.map_neg 1 end section semiring_hom variables [non_assoc_semiring R] [non_assoc_semiring S] [non_assoc_semiring S'] /-- Reinterpret a ring equivalence as a ring homomorphism. -/ def to_ring_hom (e : R ≃+* S) : R →+* S := { .. e.to_mul_equiv.to_monoid_hom, .. e.to_add_equiv.to_add_monoid_hom } lemma to_ring_hom_injective : function.injective (to_ring_hom : (R ≃+* S) → R →+* S) := λ f g h, ring_equiv.ext (ring_hom.ext_iff.1 h) instance has_coe_to_ring_hom : has_coe (R ≃+* S) (R →+* S) := ⟨ring_equiv.to_ring_hom⟩ lemma to_ring_hom_eq_coe (f : R ≃+* S) : f.to_ring_hom = ↑f := rfl @[simp, norm_cast] lemma coe_to_ring_hom (f : R ≃+* S) : ⇑(f : R →+* S) = f := rfl lemma coe_ring_hom_inj_iff {R S : Type*} [non_assoc_semiring R] [non_assoc_semiring S] (f g : R ≃+* S) : f = g ↔ (f : R →+* S) = g := ⟨congr_arg _, λ h, ext $ ring_hom.ext_iff.mp h⟩ /-- Reinterpret a ring equivalence as a monoid homomorphism. -/ abbreviation to_monoid_hom (e : R ≃+* S) : R →* S := e.to_ring_hom.to_monoid_hom /-- Reinterpret a ring equivalence as an `add_monoid` homomorphism. -/ abbreviation to_add_monoid_hom (e : R ≃+* S) : R →+ S := e.to_ring_hom.to_add_monoid_hom /-- The two paths coercion can take to an `add_monoid_hom` are equivalent -/ lemma to_add_monoid_hom_commutes (f : R ≃+* S) : (f : R →+* S).to_add_monoid_hom = (f : R ≃+ S).to_add_monoid_hom := rfl /-- The two paths coercion can take to an `monoid_hom` are equivalent -/ lemma to_monoid_hom_commutes (f : R ≃+* S) : (f : R →+* S).to_monoid_hom = (f : R ≃* S).to_monoid_hom := rfl /-- The two paths coercion can take to an `equiv` are equivalent -/ lemma to_equiv_commutes (f : R ≃+* S) : (f : R ≃+ S).to_equiv = (f : R ≃* S).to_equiv := rfl @[simp] lemma to_ring_hom_refl : (ring_equiv.refl R).to_ring_hom = ring_hom.id R := rfl @[simp] lemma to_monoid_hom_refl : (ring_equiv.refl R).to_monoid_hom = monoid_hom.id R := rfl @[simp] lemma to_add_monoid_hom_refl : (ring_equiv.refl R).to_add_monoid_hom = add_monoid_hom.id R := rfl @[simp] lemma to_ring_hom_apply_symm_to_ring_hom_apply (e : R ≃+* S) : ∀ (y : S), e.to_ring_hom (e.symm.to_ring_hom y) = y := e.to_equiv.apply_symm_apply @[simp] lemma symm_to_ring_hom_apply_to_ring_hom_apply (e : R ≃+* S) : ∀ (x : R), e.symm.to_ring_hom (e.to_ring_hom x) = x := equiv.symm_apply_apply (e.to_equiv) @[simp] lemma to_ring_hom_trans (e₁ : R ≃+* S) (e₂ : S ≃+* S') : (e₁.trans e₂).to_ring_hom = e₂.to_ring_hom.comp e₁.to_ring_hom := rfl @[simp] lemma to_ring_hom_comp_symm_to_ring_hom (e : R ≃+* S) : e.to_ring_hom.comp e.symm.to_ring_hom = ring_hom.id _ := by { ext, simp } @[simp] lemma symm_to_ring_hom_comp_to_ring_hom (e : R ≃+* S) : e.symm.to_ring_hom.comp e.to_ring_hom = ring_hom.id _ := by { ext, simp } /-- Construct an equivalence of rings from homomorphisms in both directions, which are inverses. -/ def of_hom_inv (hom : R →+* S) (inv : S →+* R) (hom_inv_id : inv.comp hom = ring_hom.id R) (inv_hom_id : hom.comp inv = ring_hom.id S) : R ≃+* S := { inv_fun := inv, left_inv := λ x, ring_hom.congr_fun hom_inv_id x, right_inv := λ x, ring_hom.congr_fun inv_hom_id x, ..hom } @[simp] lemma of_hom_inv_apply (hom : R →+* S) (inv : S →+* R) (hom_inv_id inv_hom_id) (r : R) : (of_hom_inv hom inv hom_inv_id inv_hom_id) r = hom r := rfl @[simp] lemma of_hom_inv_symm_apply (hom : R →+* S) (inv : S →+* R) (hom_inv_id inv_hom_id) (s : S) : (of_hom_inv hom inv hom_inv_id inv_hom_id).symm s = inv s := rfl end semiring_hom section big_operators lemma map_list_prod [semiring R] [semiring S] (f : R ≃+* S) (l : list R) : f l.prod = (l.map f).prod := f.to_ring_hom.map_list_prod l lemma map_list_sum [non_assoc_semiring R] [non_assoc_semiring S] (f : R ≃+* S) (l : list R) : f l.sum = (l.map f).sum := f.to_ring_hom.map_list_sum l /-- An isomorphism into the opposite ring acts on the product by acting on the reversed elements -/ lemma unop_map_list_prod [semiring R] [semiring S] (f : R ≃+* Sᵒᵖ) (l : list R) : opposite.unop (f l.prod) = (l.map (opposite.unop ∘ f)).reverse.prod := f.to_ring_hom.unop_map_list_prod l lemma map_multiset_prod [comm_semiring R] [comm_semiring S] (f : R ≃+* S) (s : multiset R) : f s.prod = (s.map f).prod := f.to_ring_hom.map_multiset_prod s lemma map_multiset_sum [non_assoc_semiring R] [non_assoc_semiring S] (f : R ≃+* S) (s : multiset R) : f s.sum = (s.map f).sum := f.to_ring_hom.map_multiset_sum s lemma map_prod {α : Type*} [comm_semiring R] [comm_semiring S] (g : R ≃+* S) (f : α → R) (s : finset α) : g (∏ x in s, f x) = ∏ x in s, g (f x) := g.to_ring_hom.map_prod f s lemma map_sum {α : Type*} [non_assoc_semiring R] [non_assoc_semiring S] (g : R ≃+* S) (f : α → R) (s : finset α) : g (∑ x in s, f x) = ∑ x in s, g (f x) := g.to_ring_hom.map_sum f s end big_operators section division_ring variables {K K' : Type*} [division_ring K] [division_ring K'] (g : K ≃+* K') (x y : K) lemma map_inv : g x⁻¹ = (g x)⁻¹ := g.to_ring_hom.map_inv x lemma map_div : g (x / y) = g x / g y := g.to_ring_hom.map_div x y end division_ring section group_power variables [semiring R] [semiring S] @[simp] lemma map_pow (f : R ≃+* S) (a) : ∀ n : ℕ, f (a ^ n) = (f a) ^ n := f.to_ring_hom.map_pow a end group_power end ring_equiv namespace mul_equiv /-- Gives a `ring_equiv` from a `mul_equiv` preserving addition.-/ def to_ring_equiv {R : Type*} {S : Type*} [has_add R] [has_add S] [has_mul R] [has_mul S] (h : R ≃* S) (H : ∀ x y : R, h (x + y) = h x + h y) : R ≃+* S := {..h.to_equiv, ..h, ..add_equiv.mk' h.to_equiv H } end mul_equiv namespace ring_equiv variables [has_add R] [has_add S] [has_mul R] [has_mul S] @[simp] theorem trans_symm (e : R ≃+* S) : e.trans e.symm = ring_equiv.refl R := ext e.3 @[simp] theorem symm_trans (e : R ≃+* S) : e.symm.trans e = ring_equiv.refl S := ext e.4 /-- If two rings are isomorphic, and the second is a domain, then so is the first. -/ protected lemma is_domain {A : Type*} (B : Type*) [ring A] [ring B] [is_domain B] (e : A ≃+* B) : is_domain A := { eq_zero_or_eq_zero_of_mul_eq_zero := λ x y hxy, have e x * e y = 0, by rw [← e.map_mul, hxy, e.map_zero], by simpa using eq_zero_or_eq_zero_of_mul_eq_zero this, exists_pair_ne := ⟨e.symm 0, e.symm 1, e.symm.injective.ne zero_ne_one⟩ } end ring_equiv
3048d8a5202706b87dcb6c1fdca74783fdc8ab73
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/data/multiset/dedup.lean
d08a5ab927d5b199b1cc5309153c8c9a5bf0cfb2
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
4,039
lean
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import data.multiset.nodup /-! # Erasing duplicates in a multiset. > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. -/ namespace multiset open list variables {α β : Type*} [decidable_eq α] /-! ### dedup -/ /-- `dedup s` removes duplicates from `s`, yielding a `nodup` multiset. -/ def dedup (s : multiset α) : multiset α := quot.lift_on s (λ l, (l.dedup : multiset α)) (λ s t p, quot.sound p.dedup) @[simp] theorem coe_dedup (l : list α) : @dedup α _ l = l.dedup := rfl @[simp] theorem dedup_zero : @dedup α _ 0 = 0 := rfl @[simp] theorem mem_dedup {a : α} {s : multiset α} : a ∈ dedup s ↔ a ∈ s := quot.induction_on s $ λ l, mem_dedup @[simp] theorem dedup_cons_of_mem {a : α} {s : multiset α} : a ∈ s → dedup (a ::ₘ s) = dedup s := quot.induction_on s $ λ l m, @congr_arg _ _ _ _ coe $ dedup_cons_of_mem m @[simp] theorem dedup_cons_of_not_mem {a : α} {s : multiset α} : a ∉ s → dedup (a ::ₘ s) = a ::ₘ dedup s := quot.induction_on s $ λ l m, congr_arg coe $ dedup_cons_of_not_mem m theorem dedup_le (s : multiset α) : dedup s ≤ s := quot.induction_on s $ λ l, (dedup_sublist _).subperm theorem dedup_subset (s : multiset α) : dedup s ⊆ s := subset_of_le $ dedup_le _ theorem subset_dedup (s : multiset α) : s ⊆ dedup s := λ a, mem_dedup.2 @[simp] theorem dedup_subset' {s t : multiset α} : dedup s ⊆ t ↔ s ⊆ t := ⟨subset.trans (subset_dedup _), subset.trans (dedup_subset _)⟩ @[simp] theorem subset_dedup' {s t : multiset α} : s ⊆ dedup t ↔ s ⊆ t := ⟨λ h, subset.trans h (dedup_subset _), λ h, subset.trans h (subset_dedup _)⟩ @[simp] theorem nodup_dedup (s : multiset α) : nodup (dedup s) := quot.induction_on s nodup_dedup theorem dedup_eq_self {s : multiset α} : dedup s = s ↔ nodup s := ⟨λ e, e ▸ nodup_dedup s, quot.induction_on s $ λ l h, congr_arg coe h.dedup⟩ alias dedup_eq_self ↔ _ nodup.dedup lemma count_dedup (m : multiset α) (a : α) : m.dedup.count a = if a ∈ m then 1 else 0 := quot.induction_on m $ λ l, count_dedup _ _ @[simp] lemma dedup_idempotent {m : multiset α} : m.dedup.dedup = m.dedup := quot.induction_on m $ λ l, @congr_arg _ _ _ _ coe dedup_idempotent @[simp] lemma dedup_bind_dedup [decidable_eq β] (m : multiset α) (f : α → multiset β) : (m.dedup.bind f).dedup = (m.bind f).dedup := by { ext x, simp_rw [count_dedup, mem_bind, mem_dedup], } theorem dedup_eq_zero {s : multiset α} : dedup s = 0 ↔ s = 0 := ⟨λ h, eq_zero_of_subset_zero $ h ▸ subset_dedup _, λ h, h.symm ▸ dedup_zero⟩ @[simp] theorem dedup_singleton {a : α} : dedup ({a} : multiset α) = {a} := (nodup_singleton _).dedup theorem le_dedup {s t : multiset α} : s ≤ dedup t ↔ s ≤ t ∧ nodup s := ⟨λ h, ⟨le_trans h (dedup_le _), nodup_of_le h (nodup_dedup _)⟩, λ ⟨l, d⟩, (le_iff_subset d).2 $ subset.trans (subset_of_le l) (subset_dedup _)⟩ theorem le_dedup_self {s : multiset α} : s ≤ dedup s ↔ nodup s := by rw [le_dedup, and_iff_right le_rfl] theorem dedup_ext {s t : multiset α} : dedup s = dedup t ↔ ∀ a, a ∈ s ↔ a ∈ t := by simp [nodup.ext] theorem dedup_map_dedup_eq [decidable_eq β] (f : α → β) (s : multiset α) : dedup (map f (dedup s)) = dedup (map f s) := by simp [dedup_ext] @[simp] lemma dedup_nsmul {s : multiset α} {n : ℕ} (h0 : n ≠ 0) : (n • s).dedup = s.dedup := begin ext a, by_cases h : a ∈ s; simp [h,h0] end lemma nodup.le_dedup_iff_le {s t : multiset α} (hno : s.nodup) : s ≤ t.dedup ↔ s ≤ t := by simp [le_dedup, hno] end multiset lemma multiset.nodup.le_nsmul_iff_le {α : Type*} {s t : multiset α} {n : ℕ} (h : s.nodup) (hn : n ≠ 0) : s ≤ n • t ↔ s ≤ t := begin classical, rw [← h.le_dedup_iff_le, iff.comm, ← h.le_dedup_iff_le], simp [hn] end
dd380e25fa6c8cc9fc4a1c5eccb920156f926d57
d9d511f37a523cd7659d6f573f990e2a0af93c6f
/src/linear_algebra/pi.lean
7ff7d9e12728a88832900eb416c006d03511916d
[ "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
13,190
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov, Eric Wieser -/ import linear_algebra.basic /-! # Pi types of modules This file defines constructors for linear maps whose domains or codomains are pi types. It contains theorems relating these to each other, as well as to `linear_map.ker`. ## Main definitions - pi types in the codomain: - `linear_map.pi` - `linear_map.single` - pi types in the domain: - `linear_map.proj` - `linear_map.diag` -/ universes u v w x y z u' v' w' x' y' variables {R : Type u} {K : Type u'} {M : Type v} {V : Type v'} {M₂ : Type w} {V₂ : Type w'} variables {M₃ : Type y} {V₃ : Type y'} {M₄ : Type z} {ι : Type x} {ι' : Type x'} open function submodule open_locale big_operators namespace linear_map universe i variables [semiring R] [add_comm_monoid M₂] [module R M₂] [add_comm_monoid M₃] [module R M₃] {φ : ι → Type i} [∀i, add_comm_monoid (φ i)] [∀i, module R (φ i)] /-- `pi` construction for linear functions. From a family of linear functions it produces a linear function into a family of modules. -/ def pi (f : Πi, M₂ →ₗ[R] φ i) : M₂ →ₗ[R] (Πi, φ i) := { to_fun := λ c i, f i c, map_add' := λ c d, funext $ λ i, (f i).map_add _ _, map_smul' := λ c d, funext $ λ i, (f i).map_smul _ _ } @[simp] lemma pi_apply (f : Πi, M₂ →ₗ[R] φ i) (c : M₂) (i : ι) : pi f c i = f i c := rfl lemma ker_pi (f : Πi, M₂ →ₗ[R] φ i) : ker (pi f) = (⨅i:ι, ker (f i)) := by ext c; simp [funext_iff]; refl lemma pi_eq_zero (f : Πi, M₂ →ₗ[R] φ i) : pi f = 0 ↔ (∀i, f i = 0) := by simp only [linear_map.ext_iff, pi_apply, funext_iff]; exact ⟨λh a b, h b a, λh a b, h b a⟩ lemma pi_zero : pi (λi, 0 : Πi, M₂ →ₗ[R] φ i) = 0 := by ext; refl lemma pi_comp (f : Πi, M₂ →ₗ[R] φ i) (g : M₃ →ₗ[R] M₂) : (pi f).comp g = pi (λi, (f i).comp g) := rfl /-- The projections from a family of modules are linear maps. Note: known here as `linear_map.proj`, this construction is in other categories called `eval`, for example `pi.eval_monoid_hom`, `pi.eval_ring_hom`. -/ def proj (i : ι) : (Πi, φ i) →ₗ[R] φ i := { to_fun := function.eval i, map_add' := λ f g, rfl, map_smul' := λ c f, rfl } @[simp] lemma coe_proj (i : ι) : ⇑(proj i : (Πi, φ i) →ₗ[R] φ i) = function.eval i := rfl lemma proj_apply (i : ι) (b : Πi, φ i) : (proj i : (Πi, φ i) →ₗ[R] φ i) b = b i := rfl lemma proj_pi (f : Πi, M₂ →ₗ[R] φ i) (i : ι) : (proj i).comp (pi f) = f i := ext $ assume c, rfl lemma infi_ker_proj : (⨅i, ker (proj i) : submodule R (Πi, φ i)) = ⊥ := bot_unique $ set_like.le_def.2 $ assume a h, begin simp only [mem_infi, mem_ker, proj_apply] at h, exact (mem_bot _).2 (funext $ assume i, h i) end /-- Linear map between the function spaces `I → M₂` and `I → M₃`, induced by a linear map `f` between `M₂` and `M₃`. -/ @[simps] protected def comp_left (f : M₂ →ₗ[R] M₃) (I : Type*) : (I → M₂) →ₗ[R] (I → M₃) := { to_fun := λ h, f ∘ h, map_smul' := λ c h, by { ext x, exact f.map_smul' c (h x) }, .. f.to_add_monoid_hom.comp_left I } lemma apply_single [add_comm_monoid M] [module R M] [decidable_eq ι] (f : Π i, φ i →ₗ[R] M) (i j : ι) (x : φ i) : f j (pi.single i x j) = pi.single i (f i x) j := pi.apply_single (λ i, f i) (λ i, (f i).map_zero) _ _ _ /-- The `linear_map` version of `add_monoid_hom.single` and `pi.single`. -/ def single [decidable_eq ι] (i : ι) : φ i →ₗ[R] (Πi, φ i) := { to_fun := pi.single i, map_smul' := pi.single_smul i, .. add_monoid_hom.single φ i} @[simp] lemma coe_single [decidable_eq ι] (i : ι) : ⇑(single i : φ i →ₗ[R] (Π i, φ i)) = pi.single i := rfl variables (R φ) /-- The linear equivalence between linear functions on a finite product of modules and families of functions on these modules. See note [bundled maps over different rings]. -/ @[simps] def lsum (S) [add_comm_monoid M] [module R M] [fintype ι] [decidable_eq ι] [semiring S] [module S M] [smul_comm_class R S M] : (Π i, φ i →ₗ[R] M) ≃ₗ[S] ((Π i, φ i) →ₗ[R] M) := { to_fun := λ f, ∑ i : ι, (f i).comp (proj i), inv_fun := λ f i, f.comp (single i), map_add' := λ f g, by simp only [pi.add_apply, add_comp, finset.sum_add_distrib], map_smul' := λ c f, by simp only [pi.smul_apply, smul_comp, finset.smul_sum], left_inv := λ f, by { ext i x, simp [apply_single] }, right_inv := λ f, begin ext, suffices : f (∑ j, pi.single j (x j)) = f x, by simpa [apply_single], rw finset.univ_sum_single end } variables {R φ} section ext variables [fintype ι] [decidable_eq ι] [add_comm_monoid M] [module R M] {f g : (Π i, φ i) →ₗ[R] M} lemma pi_ext (h : ∀ i x, f (pi.single i x) = g (pi.single i x)) : f = g := to_add_monoid_hom_injective $ add_monoid_hom.functions_ext _ _ _ h lemma pi_ext_iff : f = g ↔ ∀ i x, f (pi.single i x) = g (pi.single i x) := ⟨λ h i x, h ▸ rfl, pi_ext⟩ /-- This is used as the ext lemma instead of `linear_map.pi_ext` for reasons explained in note [partially-applied ext lemmas]. -/ @[ext] lemma pi_ext' (h : ∀ i, f.comp (single i) = g.comp (single i)) : f = g := begin refine pi_ext (λ i x, _), convert linear_map.congr_fun (h i) x end lemma pi_ext'_iff : f = g ↔ ∀ i, f.comp (single i) = g.comp (single i) := ⟨λ h i, h ▸ rfl, pi_ext'⟩ end ext section variables (R φ) /-- If `I` and `J` are disjoint index sets, the product of the kernels of the `J`th projections of `φ` is linearly equivalent to the product over `I`. -/ def infi_ker_proj_equiv {I J : set ι} [decidable_pred (λi, i ∈ I)] (hd : disjoint I J) (hu : set.univ ⊆ I ∪ J) : (⨅i ∈ J, ker (proj i) : submodule R (Πi, φ i)) ≃ₗ[R] (Πi:I, φ i) := begin refine linear_equiv.of_linear (pi $ λi, (proj (i:ι)).comp (submodule.subtype _)) (cod_restrict _ (pi $ λi, if h : i ∈ I then proj (⟨i, h⟩ : I) else 0) _) _ _, { assume b, simp only [mem_infi, mem_ker, funext_iff, proj_apply, pi_apply], assume j hjJ, have : j ∉ I := assume hjI, hd ⟨hjI, hjJ⟩, rw [dif_neg this, zero_apply] }, { simp only [pi_comp, comp_assoc, subtype_comp_cod_restrict, proj_pi, dif_pos, subtype.coe_prop], ext b ⟨j, hj⟩, refl }, { ext1 ⟨b, hb⟩, apply subtype.ext, ext j, have hb : ∀i ∈ J, b i = 0, { simpa only [mem_infi, mem_ker, proj_apply] using (mem_infi _).1 hb }, simp only [comp_apply, pi_apply, id_apply, proj_apply, subtype_apply, cod_restrict_apply], split_ifs, { refl }, { exact (hb _ $ (hu trivial).resolve_left h).symm } } end end section variable [decidable_eq ι] /-- `diag i j` is the identity map if `i = j`. Otherwise it is the constant 0 map. -/ def diag (i j : ι) : φ i →ₗ[R] φ j := @function.update ι (λj, φ i →ₗ[R] φ j) _ 0 i id j lemma update_apply (f : Πi, M₂ →ₗ[R] φ i) (c : M₂) (i j : ι) (b : M₂ →ₗ[R] φ i) : (update f i b j) c = update (λi, f i c) i (b c) j := begin by_cases j = i, { rw [h, update_same, update_same] }, { rw [update_noteq h, update_noteq h] } end end end linear_map namespace submodule variables [semiring R] {φ : ι → Type*} [∀ i, add_comm_monoid (φ i)] [∀ i, module R (φ i)] open linear_map /-- A version of `set.pi` for submodules. Given an index set `I` and a family of submodules `p : Π i, submodule R (φ i)`, `pi I s` is the submodule of dependent functions `f : Π i, φ i` such that `f i` belongs to `p a` whenever `i ∈ I`. -/ def pi (I : set ι) (p : Π i, submodule R (φ i)) : submodule R (Π i, φ i) := { carrier := set.pi I (λ i, p i), zero_mem' := λ i hi, (p i).zero_mem, add_mem' := λ x y hx hy i hi, (p i).add_mem (hx i hi) (hy i hi), smul_mem' := λ c x hx i hi, (p i).smul_mem c (hx i hi) } variables {I : set ι} {p : Π i, submodule R (φ i)} {x : Π i, φ i} @[simp] lemma mem_pi : x ∈ pi I p ↔ ∀ i ∈ I, x i ∈ p i := iff.rfl @[simp, norm_cast] lemma coe_pi : (pi I p : set (Π i, φ i)) = set.pi I (λ i, p i) := rfl lemma binfi_comap_proj : (⨅ i ∈ I, comap (proj i) (p i)) = pi I p := by { ext x, simp } lemma infi_comap_proj : (⨅ i, comap (proj i) (p i)) = pi set.univ p := by { ext x, simp } lemma supr_map_single [decidable_eq ι] [fintype ι] : (⨆ i, map (linear_map.single i) (p i)) = pi set.univ p := begin refine (supr_le $ λ i, _).antisymm _, { rintro _ ⟨x, hx : x ∈ p i, rfl⟩ j -, rcases em (j = i) with rfl|hj; simp * }, { intros x hx, rw [← finset.univ_sum_single x], exact sum_mem_supr (λ i, mem_map_of_mem (hx i trivial)) } end end submodule namespace linear_equiv variables [semiring R] {φ ψ χ : ι → Type*} [∀ i, add_comm_monoid (φ i)] [∀ i, module R (φ i)] variables [∀ i, add_comm_monoid (ψ i)] [∀ i, module R (ψ i)] variables [∀ i, add_comm_monoid (χ i)] [∀ i, module R (χ i)] /-- Combine a family of linear equivalences into a linear equivalence of `pi`-types. This is `equiv.Pi_congr_right` as a `linear_equiv` -/ @[simps apply] def Pi_congr_right (e : Π i, φ i ≃ₗ[R] ψ i) : (Π i, φ i) ≃ₗ[R] (Π i, ψ i) := { to_fun := λ f i, e i (f i), inv_fun := λ f i, (e i).symm (f i), map_smul' := λ c f, by { ext, simp }, .. add_equiv.Pi_congr_right (λ j, (e j).to_add_equiv) } @[simp] lemma Pi_congr_right_refl : Pi_congr_right (λ j, refl R (φ j)) = refl _ _ := rfl @[simp] lemma Pi_congr_right_symm (e : Π i, φ i ≃ₗ[R] ψ i) : (Pi_congr_right e).symm = (Pi_congr_right $ λ i, (e i).symm) := rfl @[simp] lemma Pi_congr_right_trans (e : Π i, φ i ≃ₗ[R] ψ i) (f : Π i, ψ i ≃ₗ[R] χ i) : (Pi_congr_right e).trans (Pi_congr_right f) = (Pi_congr_right $ λ i, (e i).trans (f i)) := rfl variables (R φ) /-- Transport dependent functions through an equivalence of the base space. This is `equiv.Pi_congr_left'` as a `linear_equiv`. -/ @[simps {simp_rhs := tt}] def Pi_congr_left' (e : ι ≃ ι') : (Π i', φ i') ≃ₗ[R] (Π i, φ $ e.symm i) := { map_add' := λ x y, rfl, map_smul' := λ x y, rfl, .. equiv.Pi_congr_left' φ e } /-- Transporting dependent functions through an equivalence of the base, expressed as a "simplification". This is `equiv.Pi_congr_left` as a `linear_equiv` -/ def Pi_congr_left (e : ι' ≃ ι) : (Π i', φ (e i')) ≃ₗ[R] (Π i, φ i) := (Pi_congr_left' R φ e.symm).symm /-- This is `equiv.pi_option_equiv_prod` as a `linear_equiv` -/ def pi_option_equiv_prod {ι : Type*} {M : option ι → Type*} [Π i, add_comm_group (M i)] [Π i, module R (M i)] : (Π i : option ι, M i) ≃ₗ[R] (M none × Π i : ι, M (some i)) := { map_add' := by simp [function.funext_iff], map_smul' := by simp [function.funext_iff], ..equiv.pi_option_equiv_prod } variables (ι R M) (S : Type*) [fintype ι] [decidable_eq ι] [semiring S] [add_comm_monoid M] [module R M] [module S M] [smul_comm_class R S M] /-- Linear equivalence between linear functions `Rⁿ → M` and `Mⁿ`. The spaces `Rⁿ` and `Mⁿ` are represented as `ι → R` and `ι → M`, respectively, where `ι` is a finite type. This as an `S`-linear equivalence, under the assumption that `S` acts on `M` commuting with `R`. When `R` is commutative, we can take this to be the usual action with `S = R`. Otherwise, `S = ℕ` shows that the equivalence is additive. See note [bundled maps over different rings]. -/ def pi_ring : ((ι → R) →ₗ[R] M) ≃ₗ[S] (ι → M) := (linear_map.lsum R (λ i : ι, R) S).symm.trans (Pi_congr_right $ λ i, linear_map.ring_lmap_equiv_self R M S) variables {ι R M} @[simp] lemma pi_ring_apply (f : (ι → R) →ₗ[R] M) (i : ι) : pi_ring R M ι S f i = f (pi.single i 1) := rfl @[simp] lemma pi_ring_symm_apply (f : ι → M) (g : ι → R) : (pi_ring R M ι S).symm f g = ∑ i, g i • f i := by simp [pi_ring, linear_map.lsum] /-- `equiv.sum_arrow_equiv_prod_arrow` as a linear equivalence. -/ -- TODO additive version? def sum_arrow_lequiv_prod_arrow (α β R M : Type*) [semiring R] [add_comm_monoid M] [module R M] : ((α ⊕ β) → M) ≃ₗ[R] (α → M) × (β → M) := { map_add' := by { intros f g, ext; refl }, map_smul' := by { intros r f, ext; refl, }, .. equiv.sum_arrow_equiv_prod_arrow α β M, } @[simp] lemma sum_arrow_lequiv_prod_arrow_apply_fst {α β} (f : (α ⊕ β) → M) (a : α) : (sum_arrow_lequiv_prod_arrow α β R M f).1 a = f (sum.inl a) := rfl @[simp] lemma sum_arrow_lequiv_prod_arrow_apply_snd {α β} (f : (α ⊕ β) → M) (b : β) : (sum_arrow_lequiv_prod_arrow α β R M f).2 b = f (sum.inr b) := rfl @[simp] lemma sum_arrow_lequiv_prod_arrow_symm_apply_inl {α β} (f : α → M) (g : β → M) (a : α) : ((sum_arrow_lequiv_prod_arrow α β R M).symm (f, g)) (sum.inl a) = f a := rfl @[simp] lemma sum_arrow_lequiv_prod_arrow_symm_apply_inr {α β} (f : α → M) (g : β → M) (b : β) : ((sum_arrow_lequiv_prod_arrow α β R M).symm (f, g)) (sum.inr b) = g b := rfl end linear_equiv
153c131b4f31490c9297b57105c7bf739f5d4a28
90bd8c2a52dbaaba588bdab57b155a7ec1532de0
/src/contractible/basic.lean
a606bc0bfecb506c1b05d00e20d7af224f550869
[ "Apache-2.0" ]
permissive
shingtaklam1324/alg-top
fd434f1478925a232af45f18f370ee3a22811c54
4c88e28df6f0a329f26eab32bae023789193990e
refs/heads/master
1,689,447,024,947
1,630,073,400,000
1,630,073,400,000
381,528,689
2
0
null
null
null
null
UTF-8
Lean
false
false
1,526
lean
import homotopy.equiv import homotopy.loop noncomputable theory class contractible (X : Type _) [topological_space X] : Prop := (hequiv : nonempty (homotopy_equiv X unit)) variables {X : Type _} [topological_space X] [contractible X] {x₀ : X} instance nonempty_of_contractible : nonempty X := begin obtain ⟨⟨f, g, h₁, h₂⟩⟩ := @contractible.hequiv X _ _, exact ⟨g ()⟩ end instance path_connected_space_of_contractible : path_connected_space X := begin refine_struct { nonempty := nonempty_of_contractible }, obtain ⟨⟨f, g, ⟨h₁⟩, h₂⟩⟩ := @contractible.hequiv X _ _, intros x y, refine ⟨path'.to_path _⟩, have : ∀ t, f t = (), { intro t, cases f t, refl }, let x₀ := g (), let p₁ : path' x₀ x, { refine_struct { to_fun := { to_fun := λ t, h₁ (x, t) } }, continuity, simp only [this, homotopy_with.to_fun_zero, continuous_map.comp_coe, continuous_map.coe_mk, function.comp_app], simp only [homotopy_with.to_fun_one, continuous_map.id_coe, id.def, continuous_map.coe_mk] }, let p₂ : path' x₀ y, { refine_struct { to_fun := { to_fun := λ t, h₁ (y, t) } }, continuity, simp only [this, homotopy_with.to_fun_zero, continuous_map.comp_coe, continuous_map.coe_mk, function.comp_app], simp only [homotopy_with.to_fun_one, continuous_map.id_coe, id.def, continuous_map.coe_mk] }, exact p₁.inv.trans p₂, recover, exact _inst_2, end . -- example : π₁ x₀ ≃* unit := -- _
85c56a95d9235333aaadee8ed3af5016718d0ba0
ae1e94c332e17c7dc7051ce976d5a9eebe7ab8a5
/src/Lean/Elab/App.lean
d6dfbc59d246b1759d7928077876befb885a1e08
[ "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
44,172
lean
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Util.FindMVar import Lean.Elab.Term import Lean.Elab.Binders import Lean.Elab.SyntheticMVars namespace Lean.Elab.Term open Meta builtin_initialize elabWithoutExpectedTypeAttr : TagAttribute ← registerTagAttribute `elabWithoutExpectedType "mark that applications of the given declaration should be elaborated without the expected type" def hasElabWithoutExpectedType (env : Environment) (declName : Name) : Bool := elabWithoutExpectedTypeAttr.hasTag env declName /-- Auxiliary inductive datatype for combining unelaborated syntax and already elaborated expressions. It is used to elaborate applications. -/ inductive Arg where | stx (val : Syntax) | expr (val : Expr) deriving Inhabited instance : ToString Arg := ⟨fun | Arg.stx val => toString val | Arg.expr val => toString val⟩ /-- Named arguments created using the notation `(x := val)` -/ structure NamedArg where ref : Syntax := Syntax.missing name : Name val : Arg deriving Inhabited instance : ToString NamedArg where toString s := "(" ++ toString s.name ++ " := " ++ toString s.val ++ ")" def throwInvalidNamedArg {α} (namedArg : NamedArg) (fn? : Option Name) : TermElabM α := withRef namedArg.ref $ match fn? with | some fn => throwError! "invalid argument name '{namedArg.name}' for function '{fn}'" | none => throwError! "invalid argument name '{namedArg.name}' for function" /-- Add a new named argument to `namedArgs`, and throw an error if it already contains a named argument with the same name. -/ def addNamedArg (namedArgs : Array NamedArg) (namedArg : NamedArg) : TermElabM (Array NamedArg) := do if namedArgs.any (namedArg.name == ·.name) then throwError! "argument '{namedArg.name}' was already set" pure $ namedArgs.push namedArg private def ensureArgType (f : Expr) (arg : Expr) (expectedType : Expr) : TermElabM Expr := do let argType ← inferType arg ensureHasTypeAux expectedType argType arg f /- Relevant definitions: ``` class CoeFun (α : Sort u) (γ : α → outParam (Sort v)) abbrev coeFun {α : Sort u} {γ : α → Sort v} (a : α) [CoeFun α γ] : γ a ``` -/ private def tryCoeFun? (α : Expr) (a : Expr) : TermElabM (Option Expr) := do let v ← mkFreshLevelMVar let type ← mkArrow α (mkSort v) let γ ← mkFreshExprMVar type let u ← getLevel α let coeFunInstType := mkAppN (Lean.mkConst `CoeFun [u, v]) #[α, γ] let mvar ← mkFreshExprMVar coeFunInstType MetavarKind.synthetic let mvarId := mvar.mvarId! try if (← synthesizeCoeInstMVarCore mvarId) then pure $ some $ mkAppN (Lean.mkConst `coeFun [u, v]) #[α, γ, a, mvar] else pure none catch _ => pure none def synthesizeAppInstMVars (instMVars : Array MVarId) : TermElabM Unit := for mvarId in instMVars do unless (← synthesizeInstMVarCore mvarId) do registerSyntheticMVarWithCurrRef mvarId SyntheticMVarKind.typeClass namespace ElabAppArgs /- Auxiliary structure for elaborating the application `f args namedArgs`. -/ structure State where explicit : Bool -- true if `@` modifier was used f : Expr fType : Expr args : List Arg -- remaining regular arguments namedArgs : List NamedArg -- remaining named arguments to be processed ellipsis : Bool := false expectedType? : Option Expr etaArgs : Array Expr := #[] toSetErrorCtx : Array MVarId := #[] -- metavariables that we need the set the error context using the application being built instMVars : Array MVarId := #[] -- metavariables for the instance implicit arguments that have already been processed -- The following field is used to implement the `propagateExpectedType` heuristic. propagateExpected : Bool -- true when expectedType has not been propagated yet abbrev M := StateRefT State TermElabM /- Add the given metavariable to the collection of metavariables associated with instance-implicit arguments. -/ private def addInstMVar (mvarId : MVarId) : M Unit := modify fun s => { s with instMVars := s.instMVars.push mvarId } /- Try to synthesize metavariables are `instMVars` using type class resolution. The ones that cannot be synthesized yet are registered. Remark: we use this method before trying to apply coercions to function. -/ def synthesizeAppInstMVars : M Unit := do let s ← get let instMVars := s.instMVars modify fun s => { s with instMVars := #[] } Lean.Elab.Term.synthesizeAppInstMVars instMVars /- fType may become a forallE after we synthesize pending metavariables. -/ private def synthesizePendingAndNormalizeFunType : M Unit := do synthesizeAppInstMVars synthesizeSyntheticMVars let s ← get let fType ← whnfForall s.fType match fType with | Expr.forallE _ _ _ _ => modify fun s => { s with fType := fType } | _ => match (← tryCoeFun? fType s.f) with | some f => let fType ← inferType f modify fun s => { s with f := f, fType := fType } | none => for namedArg in s.namedArgs do match s.f.getAppFn with | Expr.const fn .. => throwInvalidNamedArg namedArg fn | _ => throwInvalidNamedArg namedArg none throwError! "function expected at{indentExpr s.f}\nterm has type{indentExpr fType}" /- Normalize and return the function type. -/ private def normalizeFunType : M Expr := do let s ← get let fType ← whnfForall s.fType modify fun s => { s with fType := fType } pure fType /- Return the binder name at `fType`. This method assumes `fType` is a function type. -/ private def getBindingName : M Name := return (← get).fType.bindingName! /- Return the next argument expected type. This method assumes `fType` is a function type. -/ private def getArgExpectedType : M Expr := return (← get).fType.bindingDomain! def eraseNamedArgCore (namedArgs : List NamedArg) (binderName : Name) : List NamedArg := namedArgs.filter (·.name != binderName) /- Remove named argument with name `binderName` from `namedArgs`. -/ def eraseNamedArg (binderName : Name) : M Unit := modify fun s => { s with namedArgs := eraseNamedArgCore s.namedArgs binderName } /- Add a new argument to the result. That is, `f := f arg`, update `fType`. This method assumes `fType` is a function type. -/ private def addNewArg (arg : Expr) : M Unit := modify fun s => { s with f := mkApp s.f arg, fType := s.fType.bindingBody!.instantiate1 arg } /- Elaborate the given `Arg` and add it to the result. See `addNewArg`. Recall that, `Arg` may be wrapping an already elaborated `Expr`. -/ private def elabAndAddNewArg (arg : Arg) : M Unit := do let s ← get let expectedType ← getArgExpectedType match arg with | Arg.expr val => let arg ← ensureArgType s.f val expectedType addNewArg arg | Arg.stx val => let val ← elabTerm val expectedType let arg ← ensureArgType s.f val expectedType addNewArg arg /- Return true if the given type contains `OptParam` or `AutoParams` -/ private def hasOptAutoParams (type : Expr) : M Bool := do forallTelescopeReducing type fun xs type => xs.anyM fun x => do let xType ← inferType x pure $ xType.getOptParamDefault?.isSome || xType.getAutoParamTactic?.isSome /- Return true if `fType` contains `OptParam` or `AutoParams` -/ private def fTypeHasOptAutoParams : M Bool := do hasOptAutoParams (← get).fType /- Auxiliary function for retrieving the resulting type of a function application. See `propagateExpectedType`. Remark: `(explicit : Bool) == true` when `@` modifier is used. -/ private partial def getForallBody (explicit : Bool) : Nat → List NamedArg → Expr → Option Expr | i, namedArgs, type@(Expr.forallE n d b c) => match namedArgs.find? fun (namedArg : NamedArg) => namedArg.name == n with | some _ => getForallBody explicit i (eraseNamedArgCore namedArgs n) b | none => if !explicit && !c.binderInfo.isExplicit then getForallBody explicit i namedArgs b else if i > 0 then getForallBody explicit (i-1) namedArgs b else if d.isAutoParam || d.isOptParam then getForallBody explicit i namedArgs b else some type | 0, [], type => some type | _, _, _ => none private def shouldPropagateExpectedTypeFor (nextArg : Arg) : Bool := match nextArg with | Arg.expr _ => false -- it has already been elaborated | Arg.stx stx => -- TODO: make this configurable? stx.getKind != `Lean.Parser.Term.hole && stx.getKind != `Lean.Parser.Term.syntheticHole && stx.getKind != `Lean.Parser.Term.byTactic /- Auxiliary method for propagating the expected type. We call it as soon as we find the first explict argument. The goal is to propagate the expected type in applications of functions such as ```lean Add.add {α : Type u} : α → α → α List.cons {α : Type u} : α → List α → List α ``` This is particularly useful when there applicable coercions. For example, assume we have a coercion from `Nat` to `Int`, and we have `(x : Nat)` and the expected type is `List Int`. Then, if we don't use this function, the elaborator will fail to elaborate ``` List.cons x [] ``` First, the elaborator creates a new metavariable `?α` for the implicit argument `{α : Type u}`. Then, when it processes `x`, it assigns `?α := Nat`, and then obtain the resultant type `List Nat` which is **not** definitionally equal to `List Int`. We solve the problem by executing this method before we elaborate the first explicit argument (`x` in this example). This method infers that the resultant type is `List ?α` and unifies it with `List Int`. Then, when we elaborate `x`, the elaborate realizes the coercion from `Nat` to `Int` must be used, and the term ``` @List.cons Int (coe x) (@List.nil Int) ``` is produced. The method will do nothing if 1- The resultant type depends on the remaining arguments (i.e., `!eTypeBody.hasLooseBVars`). 2- The resultant type contains optional/auto params. We have considered adding the following extra conditions a) The resultant type does not contain any type metavariable. b) The resultant type contains a nontype metavariable. These two conditions would restrict the method to simple functions that are "morally" in the Hindley&Milner fragment. If users need to disable expected type propagation, we can add an attribute `[elabWithoutExpectedType]`. -/ private def propagateExpectedType (arg : Arg) : M Unit := do if shouldPropagateExpectedTypeFor arg then let s ← get -- TODO: handle s.etaArgs.size > 0 unless !s.etaArgs.isEmpty || !s.propagateExpected do match s.expectedType? with | none => pure () | some expectedType => /- We don't propagate `Prop` because we often use `Prop` as a more general "Bool" (e.g., `if-then-else`). If we propagate `expectedType == Prop` in the following examples, the elaborator would fail ``` def f1 (s : Nat × Bool) : Bool := if s.2 then false else true def f2 (s : List Bool) : Bool := if s.head! then false else true def f3 (s : List Bool) : Bool := if List.head! (s.map not) then false else true ``` They would all fail for the same reason. So, let's focus on the first one. We would elaborate `s.2` with `expectedType == Prop`. Before we elaborate `s`, this method would be invoked, and `s.fType` is `?α × ?β → ?β` and after propagation we would have `?α × Prop → Prop`. Then, when we would try to elaborate `s`, and get a type error because `?α × Prop` cannot be unified with `Nat × Bool` Most users would have a hard time trying to understand why these examples failed. Here is a possible alternative workarounds. We give up the idea of using `Prop` at `if-then-else`. Drawback: users use `if-then-else` with conditions that are not Decidable. So, users would have to embrace `propDecidable` and `choice`. This may not be that bad since the developers and users don't seem to care about constructivism. We currently use a different workaround, we just don't propagate the expected type when it is `Prop`. -/ if expectedType.isProp then modify fun s => { s with propagateExpected := false } else let numRemainingArgs := s.args.length trace[Elab.app.propagateExpectedType]! "etaArgs.size: {s.etaArgs.size}, numRemainingArgs: {numRemainingArgs}, fType: {s.fType}" match getForallBody s.explicit numRemainingArgs s.namedArgs s.fType with | none => pure () | some fTypeBody => unless fTypeBody.hasLooseBVars do unless (← hasOptAutoParams fTypeBody) do trace[Elab.app.propagateExpectedType]! "{expectedType} =?= {fTypeBody}" if (← isDefEq expectedType fTypeBody) then /- Note that we only set `propagateExpected := false` when propagation has succeeded. -/ modify fun s => { s with propagateExpected := false } /- Create a fresh local variable with the current binder name and argument type, add it to `etaArgs` and `f`, and then execute the continuation `k`.-/ private def addEtaArg (k : M Expr) : M Expr := do let n ← getBindingName let type ← getArgExpectedType withLocalDeclD n type fun x => do modify fun s => { s with etaArgs := s.etaArgs.push x } addNewArg x k /- This method execute after all application arguments have been processed. -/ private def finalize : M Expr := do let s ← get let mut e := s.f -- all user explicit arguments have been consumed trace[Elab.app.finalize]! e let ref ← getRef -- Register the error context of implicits for mvarId in s.toSetErrorCtx do registerMVarErrorImplicitArgInfo mvarId ref e if !s.etaArgs.isEmpty then e ← mkLambdaFVars s.etaArgs e /- Remark: we should not use `s.fType` as `eType` even when `s.etaArgs.isEmpty`. Reason: it may have been unfolded. -/ let eType ← inferType e trace[Elab.app.finalize]! "after etaArgs, {e} : {eType}" match s.expectedType? with | none => pure () | some expectedType => trace[Elab.app.finalize]! "expected type: {expectedType}" -- Try to propagate expected type. Ignore if types are not definitionally equal, caller must handle it. discard <| isDefEq expectedType eType synthesizeAppInstMVars pure e private def addImplicitArg (k : M Expr) : M Expr := do let argType ← getArgExpectedType let arg ← mkFreshExprMVar argType if (← isTypeFormer arg) then modify fun s => { s with toSetErrorCtx := s.toSetErrorCtx.push arg.mvarId! } addNewArg arg k /- Return true if there is a named argument that depends on the next argument. -/ private def anyNamedArgDependsOnCurrent : M Bool := do let s ← get if s.namedArgs.isEmpty then return false else forallTelescopeReducing s.fType fun xs _ => do let curr := xs[0] for i in [1:xs.size] do let xDecl ← getLocalDecl xs[i].fvarId! if s.namedArgs.any fun arg => arg.name == xDecl.userName then if (← getMCtx).localDeclDependsOn xDecl curr.fvarId! then return true return false /- Process a `fType` of the form `(x : A) → B x`. This method assume `fType` is a function type -/ private def processExplictArg (k : M Expr) : M Expr := do let s ← get match s.args with | arg::args => propagateExpectedType arg modify fun s => { s with args := args } elabAndAddNewArg arg k | _ => let argType ← getArgExpectedType match s.explicit, argType.getOptParamDefault?, argType.getAutoParamTactic? with | false, some defVal, _ => addNewArg defVal; k | false, _, some (Expr.const tacticDecl _ _) => let env ← getEnv let opts ← getOptions match evalSyntaxConstant env opts tacticDecl with | Except.error err => throwError err | Except.ok tacticSyntax => -- TODO(Leo): does this work correctly for tactic sequences? let tacticBlock ← `(by $tacticSyntax) -- tacticBlock does not have any position information. -- So, we use the current ref let ref ← getRef let tacticBlock := tacticBlock.copyInfo ref let argType := argType.getArg! 0 -- `autoParam type := by tactic` ==> `type` let argNew := Arg.stx tacticBlock propagateExpectedType argNew elabAndAddNewArg argNew k | false, _, some _ => throwError "invalid autoParam, argument must be a constant" | _, _, _ => if !s.namedArgs.isEmpty then if (← anyNamedArgDependsOnCurrent) then addImplicitArg k else addEtaArg k else if !s.explicit then if (← fTypeHasOptAutoParams) then addEtaArg k else if (← get).ellipsis then addImplicitArg k else finalize else finalize /- Process a `fType` of the form `{x : A} → B x`. This method assume `fType` is a function type -/ private def processImplicitArg (k : M Expr) : M Expr := do if (← get).explicit then processExplictArg k else addImplicitArg k /- Return true if the next argument at `args` is of the form `_` -/ private def isNextArgHole : M Bool := do match (← get).args with | Arg.stx (Syntax.node `Lean.Parser.Term.hole _) :: _ => pure true | _ => pure false /- Process a `fType` of the form `[x : A] → B x`. This method assume `fType` is a function type -/ private def processInstImplicitArg (k : M Expr) : M Expr := do if (← get).explicit then if (← isNextArgHole) then /- Recall that if '@' has been used, and the argument is '_', then we still use type class resolution -/ let arg ← mkFreshExprMVar (← getArgExpectedType) MetavarKind.synthetic modify fun s => { s with args := s.args.tail! } addInstMVar arg.mvarId! addNewArg arg k else processExplictArg k else let arg ← mkFreshExprMVar (← getArgExpectedType) MetavarKind.synthetic addInstMVar arg.mvarId! addNewArg arg k /- Return true if there are regular or named arguments to be processed. -/ private def hasArgsToProcess : M Bool := do let s ← get pure $ !s.args.isEmpty || !s.namedArgs.isEmpty /- Elaborate function application arguments. -/ partial def main : M Expr := do let s ← get let fType ← normalizeFunType match fType with | Expr.forallE binderName _ _ c => let s ← get match s.namedArgs.find? fun (namedArg : NamedArg) => namedArg.name == binderName with | some namedArg => propagateExpectedType namedArg.val eraseNamedArg binderName elabAndAddNewArg namedArg.val main | none => match c.binderInfo with | BinderInfo.implicit => processImplicitArg main | BinderInfo.instImplicit => processInstImplicitArg main | _ => processExplictArg main | _ => if (← hasArgsToProcess) then synthesizePendingAndNormalizeFunType main else finalize end ElabAppArgs private def propagateExpectedTypeFor (f : Expr) : TermElabM Bool := match f.getAppFn with | Expr.const declName .. => return !hasElabWithoutExpectedType (← getEnv) declName | _ => return true private def elabAppArgs (f : Expr) (namedArgs : Array NamedArg) (args : Array Arg) (expectedType? : Option Expr) (explicit ellipsis : Bool) : TermElabM Expr := do let fType ← inferType f let fType ← instantiateMVars fType trace[Elab.app.args]! "explicit: {explicit}, {f} : {fType}" unless namedArgs.isEmpty && args.isEmpty do tryPostponeIfMVar fType ElabAppArgs.main.run' { args := args.toList, expectedType? := expectedType?, explicit := explicit, ellipsis := ellipsis, namedArgs := namedArgs.toList, f := f, fType := fType propagateExpected := (← propagateExpectedTypeFor f) } /-- Auxiliary inductive datatype that represents the resolution of an `LVal`. -/ inductive LValResolution where | projFn (baseStructName : Name) (structName : Name) (fieldName : Name) | projIdx (structName : Name) (idx : Nat) | const (baseStructName : Name) (structName : Name) (constName : Name) | localRec (baseName : Name) (fullName : Name) (fvar : Expr) | getOp (fullName : Name) (idx : Syntax) private def throwLValError {α} (e : Expr) (eType : Expr) (msg : MessageData) : TermElabM α := throwError! "{msg}{indentExpr e}\nhas type{indentExpr eType}" /-- `findMethod? env S fName`. 1- If `env` contains `S ++ fName`, return `(S, S++fName)` 2- Otherwise if `env` contains private name `prv` for `S ++ fName`, return `(S, prv)`, o 3- Otherwise for each parent structure `S'` of `S`, we try `findMethod? env S' fname` -/ private partial def findMethod? (env : Environment) (structName fieldName : Name) : Option (Name × Name) := let fullName := structName ++ fieldName match env.find? fullName with | some _ => some (structName, fullName) | none => let fullNamePrv := mkPrivateName env fullName match env.find? fullNamePrv with | some _ => some (structName, fullNamePrv) | none => if isStructureLike env structName then (getParentStructures env structName).findSome? fun parentStructName => findMethod? env parentStructName fieldName else none private def resolveLValAux (e : Expr) (eType : Expr) (lval : LVal) : TermElabM LValResolution := do match eType.getAppFn, lval with | Expr.const structName _ _, LVal.fieldIdx _ idx => if idx == 0 then throwError "invalid projection, index must be greater than 0" let env ← getEnv unless isStructureLike env structName do throwLValError e eType "invalid projection, structure expected" let fieldNames := getStructureFields env structName if h : idx - 1 < fieldNames.size then if isStructure env structName then pure $ LValResolution.projFn structName structName (fieldNames.get ⟨idx - 1, h⟩) else /- `structName` was declared using `inductive` command. So, we don't projection functions for it. Thus, we use `Expr.proj` -/ pure $ LValResolution.projIdx structName (idx - 1) else throwLValError e eType m!"invalid projection, structure has only {fieldNames.size} field(s)" | Expr.const structName _ _, LVal.fieldName _ fieldName => let env ← getEnv let searchEnv : Unit → TermElabM LValResolution := fun _ => do match findMethod? env structName (Name.mkSimple fieldName) with | some (baseStructName, fullName) => pure $ LValResolution.const baseStructName structName fullName | none => throwLValError e eType m!"invalid field notation, '{fieldName}' is not a valid \"field\" because environment does not contain '{Name.mkStr structName fieldName}'" -- search local context first, then environment let searchCtx : Unit → TermElabM LValResolution := fun _ => do let fullName := Name.mkStr structName fieldName let currNamespace ← getCurrNamespace let localName := fullName.replacePrefix currNamespace Name.anonymous let lctx ← getLCtx match lctx.findFromUserName? localName with | some localDecl => if localDecl.binderInfo == BinderInfo.auxDecl then /- LVal notation is being used to make a "local" recursive call. -/ pure $ LValResolution.localRec structName fullName localDecl.toExpr else searchEnv () | none => searchEnv () if isStructure env structName then match findField? env structName (Name.mkSimple fieldName) with | some baseStructName => pure $ LValResolution.projFn baseStructName structName (Name.mkSimple fieldName) | none => searchCtx () else searchCtx () | Expr.const structName _ _, LVal.getOp _ idx => let env ← getEnv let fullName := Name.mkStr structName "getOp" match env.find? fullName with | some _ => pure $ LValResolution.getOp fullName idx | none => throwLValError e eType m!"invalid [..] notation because environment does not contain '{fullName}'" | _, LVal.getOp _ idx => throwLValError e eType "invalid [..] notation, type is not of the form (C ...) where C is a constant" | _, _ => throwLValError e eType "invalid field notation, type is not of the form (C ...) where C is a constant" /- whnfCore + implicit consumption. Example: given `e` with `eType := {α : Type} → (fun β => List β) α `, it produces `(e ?m, List ?m)` where `?m` is fresh metavariable. -/ private partial def consumeImplicits (e eType : Expr) : TermElabM (Expr × Expr) := do let eType ← whnfCore eType match eType with | Expr.forallE n d b c => if !c.binderInfo.isExplicit then let mvar ← mkFreshExprMVar d consumeImplicits (mkApp e mvar) (b.instantiate1 mvar) else match d.getOptParamDefault? with | some defVal => consumeImplicits (mkApp e defVal) (b.instantiate1 defVal) -- TODO: we do not handle autoParams here. | _ => pure (e, eType) | _ => pure (e, eType) private partial def resolveLValLoop (lval : LVal) (e eType : Expr) (previousExceptions : Array Exception) : TermElabM (Expr × LValResolution) := do let (e, eType) ← consumeImplicits e eType tryPostponeIfMVar eType try let lvalRes ← resolveLValAux e eType lval pure (e, lvalRes) catch | ex@(Exception.error _ _) => let eType? ← unfoldDefinition? eType match eType? with | some eType => resolveLValLoop lval e eType (previousExceptions.push ex) | none => previousExceptions.forM fun ex => logException ex throw ex | ex@(Exception.internal _ _) => throw ex private def resolveLVal (e : Expr) (lval : LVal) : TermElabM (Expr × LValResolution) := do let eType ← inferType e resolveLValLoop lval e eType #[] private partial def mkBaseProjections (baseStructName : Name) (structName : Name) (e : Expr) : TermElabM Expr := do let env ← getEnv match getPathToBaseStructure? env baseStructName structName with | none => throwError "failed to access field in parent structure" | some path => let mut e := e for projFunName in path do let projFn ← mkConst projFunName e ← elabAppArgs projFn #[{ name := `self, val := Arg.expr e }] (args := #[]) (expectedType? := none) (explicit := false) (ellipsis := false) return e /- Auxiliary method for field notation. It tries to add `e` as a new argument to `args` or `namedArgs`. This method first finds the parameter with a type of the form `(baseName ...)`. When the parameter is found, if it an explicit one and `args` is big enough, we add `e` to `args`. Otherwise, if there isn't another parameter with the same name, we add `e` to `namedArgs`. Remark: `fullName` is the name of the resolved "field" access function. It is used for reporting errors -/ private def addLValArg (baseName : Name) (fullName : Name) (e : Expr) (args : Array Arg) (namedArgs : Array NamedArg) (fType : Expr) : TermElabM (Array Arg × Array NamedArg) := forallTelescopeReducing fType fun xs _ => do let mut argIdx := 0 -- position of the next explicit argument let mut remainingNamedArgs := namedArgs for i in [:xs.size] do let x := xs[i] let xDecl ← getLocalDecl x.fvarId! /- If there is named argument with name `xDecl.userName`, then we skip it. -/ match remainingNamedArgs.findIdx? (fun namedArg => namedArg.name == xDecl.userName) with | some idx => remainingNamedArgs := remainingNamedArgs.eraseIdx idx | none => let mut foundIt := false let type := xDecl.type if type.consumeMData.isAppOf baseName then foundIt := true if !foundIt then /- Normalize type and try again -/ let type ← withReducible $ whnf type if type.consumeMData.isAppOf baseName then foundIt := true if foundIt then /- We found a type of the form (baseName ...). First, we check if the current argument is an explicit one, and the current explicit position "fits" at `args` (i.e., it must be ≤ arg.size) -/ if argIdx ≤ args.size && xDecl.binderInfo.isExplicit then /- We insert `e` as an explicit argument -/ return (args.insertAt argIdx (Arg.expr e), namedArgs) /- If we can't add `e` to `args`, we try to add it using a named argument, but this is only possible if there isn't an argument with the same name occurring before it. -/ for j in [:i] do let prev := xs[j] let prevDecl ← getLocalDecl prev.fvarId! if prevDecl.userName == xDecl.userName then throwError! "invalid field notation, function '{fullName}' has argument with the expected type{indentExpr type}\nbut it cannot be used" return (args, namedArgs.push { name := xDecl.userName, val := Arg.expr e }) if xDecl.binderInfo.isExplicit then -- advance explicit argument position argIdx := argIdx + 1 throwError! "invalid field notation, function '{fullName}' does not have argument with type ({baseName} ...) that can be used, it must be explicit or implicit with an unique name" private def elabAppLValsAux (namedArgs : Array NamedArg) (args : Array Arg) (expectedType? : Option Expr) (explicit ellipsis : Bool) (f : Expr) (lvals : List LVal) : TermElabM Expr := let rec loop : Expr → List LVal → TermElabM Expr | f, [] => elabAppArgs f namedArgs args expectedType? explicit ellipsis | f, lval::lvals => do let (f, lvalRes) ← resolveLVal f lval match lvalRes with | LValResolution.projIdx structName idx => let f := mkProj structName idx f addTermInfo lval.getRef f loop f lvals | LValResolution.projFn baseStructName structName fieldName => let f ← mkBaseProjections baseStructName structName f let projFn ← mkConst (baseStructName ++ fieldName) addTermInfo lval.getRef projFn if lvals.isEmpty then let namedArgs ← addNamedArg namedArgs { name := `self, val := Arg.expr f } elabAppArgs projFn namedArgs args expectedType? explicit ellipsis else let f ← elabAppArgs projFn #[{ name := `self, val := Arg.expr f }] #[] (expectedType? := none) (explicit := false) (ellipsis := false) loop f lvals | LValResolution.const baseStructName structName constName => let f ← if baseStructName != structName then mkBaseProjections baseStructName structName f else pure f let projFn ← mkConst constName addTermInfo lval.getRef projFn if lvals.isEmpty then let projFnType ← inferType projFn let (args, namedArgs) ← addLValArg baseStructName constName f args namedArgs projFnType elabAppArgs projFn namedArgs args expectedType? explicit ellipsis else let f ← elabAppArgs projFn #[] #[Arg.expr f] (expectedType? := none) (explicit := false) (ellipsis := false) loop f lvals | LValResolution.localRec baseName fullName fvar => addTermInfo lval.getRef fvar if lvals.isEmpty then let fvarType ← inferType fvar let (args, namedArgs) ← addLValArg baseName fullName f args namedArgs fvarType elabAppArgs fvar namedArgs args expectedType? explicit ellipsis else let f ← elabAppArgs fvar #[] #[Arg.expr f] (expectedType? := none) (explicit := false) (ellipsis := false) loop f lvals | LValResolution.getOp fullName idx => let getOpFn ← mkConst fullName addTermInfo lval.getRef getOpFn if lvals.isEmpty then let namedArgs ← addNamedArg namedArgs { name := `self, val := Arg.expr f } let namedArgs ← addNamedArg namedArgs { name := `idx, val := Arg.stx idx } elabAppArgs getOpFn namedArgs args expectedType? explicit ellipsis else let f ← elabAppArgs getOpFn #[{ name := `self, val := Arg.expr f }, { name := `idx, val := Arg.stx idx }] #[] (expectedType? := none) (explicit := false) (ellipsis := false) loop f lvals loop f lvals private def elabAppLVals (f : Expr) (lvals : List LVal) (namedArgs : Array NamedArg) (args : Array Arg) (expectedType? : Option Expr) (explicit ellipsis : Bool) : TermElabM Expr := do if !lvals.isEmpty && explicit then throwError "invalid use of field notation with `@` modifier" elabAppLValsAux namedArgs args expectedType? explicit ellipsis f lvals def elabExplicitUnivs (lvls : Array Syntax) : TermElabM (List Level) := do lvls.foldrM (fun stx lvls => do pure ((← elabLevel stx)::lvls)) [] /- Interaction between `errToSorry` and `observing`. - The method `elabTerm` catches exceptions, log them, and returns a synthetic sorry (IF `ctx.errToSorry` == true). - When we elaborate choice nodes (and overloaded identifiers), we track multiple results using the `observing x` combinator. The `observing x` executes `x` and returns a `TermElabResult`. `observing `x does not check for synthetic sorry's, just an exception. Thus, it may think `x` worked when it didn't if a synthetic sorry was introduced. We decided that checking for synthetic sorrys at `observing` is not a good solution because it would not be clear to decide what the "main" error message for the alternative is. When the result contains a synthetic `sorry`, it is not clear which error message corresponds to the `sorry`. Moreover, while executing `x`, many error messages may have been logged. Recall that we need an error per alternative at `mergeFailures`. Thus, we decided to set `errToSorry` to `false` whenever processing choice nodes and overloaded symbols. Important: we rely on the property that after `errToSorry` is set to false, no elaboration function executed by `x` will reset it to `true`. -/ private partial def elabAppFnId (fIdent : Syntax) (fExplicitUnivs : List Level) (lvals : List LVal) (namedArgs : Array NamedArg) (args : Array Arg) (expectedType? : Option Expr) (explicit ellipsis overloaded : Bool) (acc : Array TermElabResult) : TermElabM (Array TermElabResult) := do match fIdent with | Syntax.ident _ _ n preresolved => let funLVals ← withRef fIdent $ resolveName n preresolved fExplicitUnivs let overloaded := overloaded || funLVals.length > 1 -- Set `errToSorry` to `false` if `funLVals` > 1. See comment above about the interaction between `errToSorry` and `observing`. withReader (fun ctx => { ctx with errToSorry := funLVals.length == 1 && ctx.errToSorry }) do funLVals.foldlM (init := acc) fun acc ⟨f, fields⟩ => do unless lvals.isEmpty && args.isEmpty && namedArgs.isEmpty do addTermInfo fIdent f let lvals' := fields.map (LVal.fieldName fIdent) let s ← observing do let e ← elabAppLVals f (lvals' ++ lvals) namedArgs args expectedType? explicit ellipsis if overloaded then ensureHasType expectedType? e else pure e pure $ acc.push s | _ => throwUnsupportedSyntax private partial def elabAppFn (f : Syntax) (lvals : List LVal) (namedArgs : Array NamedArg) (args : Array Arg) (expectedType? : Option Expr) (explicit ellipsis overloaded : Bool) (acc : Array TermElabResult) : TermElabM (Array TermElabResult) := if f.getKind == choiceKind then -- Set `errToSorry` to `false` when processing choice nodes. See comment above about the interaction between `errToSorry` and `observing`. withReader (fun ctx => { ctx with errToSorry := false }) do f.getArgs.foldlM (fun acc f => elabAppFn f lvals namedArgs args expectedType? explicit ellipsis true acc) acc else match f with | `($(e).$idxStx:fieldIdx) => let idx := idxStx.isFieldIdx?.get! elabAppFn e (LVal.fieldIdx idxStx idx :: lvals) namedArgs args expectedType? explicit ellipsis overloaded acc | `($e |>. $field) => do let f ← `($(e).$field) elabAppFn f lvals namedArgs args expectedType? explicit ellipsis overloaded acc | `($(e).$field:ident) => let newLVals := field.getId.eraseMacroScopes.components.map (fun n => LVal.fieldName field (toString n)) elabAppFn e (newLVals ++ lvals) namedArgs args expectedType? explicit ellipsis overloaded acc | `($e[%$bracket $idx]) => elabAppFn e (LVal.getOp bracket idx :: lvals) namedArgs args expectedType? explicit ellipsis overloaded acc | `($id:ident@$t:term) => throwError "unexpected occurrence of named pattern" | `($id:ident) => do elabAppFnId id [] lvals namedArgs args expectedType? explicit ellipsis overloaded acc | `($id:ident.{$us,*}) => do let us ← elabExplicitUnivs us elabAppFnId id us lvals namedArgs args expectedType? explicit ellipsis overloaded acc | `(@$id:ident) => elabAppFn id lvals namedArgs args expectedType? (explicit := true) ellipsis overloaded acc | `(@$id:ident.{$us,*}) => elabAppFn (f.getArg 1) lvals namedArgs args expectedType? (explicit := true) ellipsis overloaded acc | `(@$t) => throwUnsupportedSyntax -- invalid occurrence of `@` | `(_) => throwError "placeholders '_' cannot be used where a function is expected" | _ => do let catchPostpone := !overloaded /- If we are processing a choice node, then we should use `catchPostpone == false` when elaborating terms. Recall that `observing` does not catch `postponeExceptionId`. -/ if lvals.isEmpty && namedArgs.isEmpty && args.isEmpty then /- Recall that elabAppFn is used for elaborating atomics terms **and** choice nodes that may contain arbitrary terms. If they are not being used as a function, we should elaborate using the expectedType. -/ let s ← if overloaded then observing $ elabTermEnsuringType f expectedType? catchPostpone else observing $ elabTerm f expectedType? pure $ acc.push s else let s ← observing do let f ← elabTerm f none catchPostpone let e ← elabAppLVals f lvals namedArgs args expectedType? explicit ellipsis if overloaded then ensureHasType expectedType? e else pure e pure $ acc.push s private def isSuccess (candidate : TermElabResult) : Bool := match candidate with | EStateM.Result.ok _ _ => true | _ => false private def getSuccess (candidates : Array TermElabResult) : Array TermElabResult := candidates.filter isSuccess private def toMessageData (ex : Exception) : TermElabM MessageData := do let pos ← getRefPos match ex.getRef.getPos with | none => pure ex.toMessageData | some exPos => if pos == exPos then pure ex.toMessageData else let exPosition := (← getFileMap).toPosition exPos pure m!"{exPosition.line}:{exPosition.column} {ex.toMessageData}" private def toMessageList (msgs : Array MessageData) : MessageData := indentD (MessageData.joinSep msgs.toList m!"\n\n") private def mergeFailures {α} (failures : Array TermElabResult) : TermElabM α := do let msgs ← failures.mapM fun failure => match failure with | EStateM.Result.ok _ _ => unreachable! | EStateM.Result.error ex _ => toMessageData ex throwError! "overloaded, errors {toMessageList msgs}" private def elabAppAux (f : Syntax) (namedArgs : Array NamedArg) (args : Array Arg) (ellipsis : Bool) (expectedType? : Option Expr) : TermElabM Expr := do let candidates ← elabAppFn f [] namedArgs args expectedType? (explicit := false) (ellipsis := ellipsis) (overloaded := false) #[] if candidates.size == 1 then applyResult candidates[0] else let successes := getSuccess candidates if successes.size == 1 then let e ← applyResult successes[0] pure e else if successes.size > 1 then let lctx ← getLCtx let opts ← getOptions let msgs : Array MessageData := successes.map fun success => match success with | EStateM.Result.ok e s => MessageData.withContext { env := s.core.env, mctx := s.meta.mctx, lctx := lctx, opts := opts } e | _ => unreachable! throwErrorAt! f "ambiguous, possible interpretations {toMessageList msgs}" else withRef f $ mergeFailures candidates partial def expandApp (stx : Syntax) (pattern := false) : TermElabM (Syntax × Array NamedArg × Array Arg × Bool) := do let f := stx[0] let args := stx[1].getArgs let (args, ellipsis) := if args.isEmpty then (args, false) else if args.back.isOfKind `Lean.Parser.Term.ellipsis then (args.pop, true) else (args, false) let (namedArgs, args) ← args.foldlM (init := (#[], #[])) fun (namedArgs, args) stx => do if stx.getKind == `Lean.Parser.Term.namedArgument then -- tparser! try ("(" >> ident >> " := ") >> termParser >> ")" let name := stx[1].getId.eraseMacroScopes let val := stx[3] let namedArgs ← addNamedArg namedArgs { ref := stx, name := name, val := Arg.stx val } pure (namedArgs, args) else if stx.getKind == `Lean.Parser.Term.ellipsis then throwErrorAt stx "unexpected '..'" else pure (namedArgs, args.push $ Arg.stx stx) pure (f, namedArgs, args, ellipsis) @[builtinTermElab app] def elabApp : TermElab := fun stx expectedType? => withoutPostponingUniverseConstraints do let (f, namedArgs, args, ellipsis) ← expandApp stx elabAppAux f namedArgs args (ellipsis := ellipsis) expectedType? private def elabAtom : TermElab := fun stx expectedType? => elabAppAux stx #[] #[] (ellipsis := false) expectedType? @[builtinTermElab ident] def elabIdent : TermElab := elabAtom @[builtinTermElab namedPattern] def elabNamedPattern : TermElab := elabAtom @[builtinTermElab explicitUniv] def elabExplicitUniv : TermElab := elabAtom @[builtinTermElab pipeProj] def expandPipeProj : TermElab := elabAtom @[builtinTermElab explicit] def elabExplicit : TermElab := fun stx expectedType? => match stx with | `(@$id:ident) => elabAtom stx expectedType? -- Recall that `elabApp` also has support for `@` | `(@$id:ident.{$us,*}) => elabAtom stx expectedType? | `(@($t)) => elabTermWithoutImplicitLambdas t expectedType? -- `@` is being used just to disable implicit lambdas | `(@$t) => elabTermWithoutImplicitLambdas t expectedType? -- `@` is being used just to disable implicit lambdas | _ => throwUnsupportedSyntax @[builtinTermElab choice] def elabChoice : TermElab := elabAtom @[builtinTermElab proj] def elabProj : TermElab := elabAtom @[builtinTermElab arrayRef] def elabArrayRef : TermElab := elabAtom @[builtinTermElab binrel] def elabBinRel : TermElab := fun stx expectedType? => do match (← resolveId? stx[1]) with | some f => let (lhs, rhs) ← withSynthesize (mayPostpone := true) do let mut lhs ← elabTerm stx[2] none let mut rhs ← elabTerm stx[3] none if lhs.isAppOfArity `OfNat.ofNat 3 then lhs ← ensureHasType (← inferType rhs) lhs else if rhs.isAppOfArity `OfNat.ofNat 3 then rhs ← ensureHasType (← inferType lhs) rhs return (lhs, rhs) let lhsType ← inferType lhs let rhsType ← inferType rhs let (lhs, rhs) ← try pure (lhs, ← withRef stx[3] do ensureHasType lhsType rhs) catch ex => try pure (← withRef stx[2] do ensureHasType rhsType lhs, rhs) catch _ => throw ex elabAppArgs f #[] #[Arg.expr lhs, Arg.expr rhs] expectedType? (explicit := false) (ellipsis := false) | none => throwUnknownConstant stx[1].getId builtin_initialize registerTraceClass `Elab.app end Lean.Elab.Term
2dcad3db4c561ac540a4b22b8df36c9044bd86de
dd0f5513e11c52db157d2fcc8456d9401a6cd9da
/12_Axioms.org.22.lean
9876d355b584525bef1e544db9212c37d2923ff9
[]
no_license
cjmazey/lean-tutorial
ba559a49f82aa6c5848b9bf17b7389bf7f4ba645
381f61c9fcac56d01d959ae0fa6e376f2c4e3b34
refs/heads/master
1,610,286,098,832
1,447,124,923,000
1,447,124,923,000
43,082,433
0
0
null
null
null
null
UTF-8
Lean
false
false
204
lean
import standard -- BEGIN import logic.eq open classical eq.ops section parameter p : Prop definition U (x : Prop) : Prop := x = true ∨ p definition V (x : Prop) : Prop := x = false ∨ p -- END end
fa555c7b805b7c4fe7670bc8082b6a698d860642
4727251e0cd73359b15b664c3170e5d754078599
/src/linear_algebra/alternating.lean
f12c372a957e74425016e64f6e37fcd7627e852f
[ "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
35,137
lean
/- Copyright (c) 2020 Zhangir Azerbayev. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser, Zhangir Azerbayev -/ import group_theory.perm.sign import group_theory.perm.subgroup import group_theory.quotient_group import linear_algebra.linear_independent import linear_algebra.multilinear.basis import linear_algebra.multilinear.tensor_product import logic.equiv.fin /-! # Alternating Maps We construct the bundled function `alternating_map`, which extends `multilinear_map` with all the arguments of the same type. ## Main definitions * `alternating_map R M N ι` is the space of `R`-linear alternating maps from `ι → M` to `N`. * `f.map_eq_zero_of_eq` expresses that `f` is zero when two inputs are equal. * `f.map_swap` expresses that `f` is negated when two inputs are swapped. * `f.map_perm` expresses how `f` varies by a sign change under a permutation of its inputs. * An `add_comm_monoid`, `add_comm_group`, and `module` structure over `alternating_map`s that matches the definitions over `multilinear_map`s. * `multilinear_map.alternatization`, which makes an alternating map out of a non-alternating one. * `alternating_map.dom_coprod`, which behaves as a product between two alternating maps. ## Implementation notes `alternating_map` is defined in terms of `map_eq_zero_of_eq`, as this is easier to work with than using `map_swap` as a definition, and does not require `has_neg N`. `alternating_map`s are provided with a coercion to `multilinear_map`, along with a set of `norm_cast` lemmas that act on the algebraic structure: * `alternating_map.coe_add` * `alternating_map.coe_zero` * `alternating_map.coe_sub` * `alternating_map.coe_neg` * `alternating_map.coe_smul` -/ -- semiring / add_comm_monoid variables {R : Type*} [semiring R] variables {M : Type*} [add_comm_monoid M] [module R M] variables {N : Type*} [add_comm_monoid N] [module R N] -- semiring / add_comm_group variables {M' : Type*} [add_comm_group M'] [module R M'] variables {N' : Type*} [add_comm_group N'] [module R N'] variables {ι : Type*} [decidable_eq ι] set_option old_structure_cmd true section variables (R M N ι) /-- An alternating map is a multilinear map that vanishes when two of its arguments are equal. -/ structure alternating_map extends multilinear_map R (λ i : ι, M) N := (map_eq_zero_of_eq' : ∀ (v : ι → M) (i j : ι) (h : v i = v j) (hij : i ≠ j), to_fun v = 0) end /-- The multilinear map associated to an alternating map -/ add_decl_doc alternating_map.to_multilinear_map namespace alternating_map variables (f f' : alternating_map R M N ι) variables (g g₂ : alternating_map R M N' ι) variables (g' : alternating_map R M' N' ι) variables (v : ι → M) (v' : ι → M') open function /-! Basic coercion simp lemmas, largely copied from `ring_hom` and `multilinear_map` -/ section coercions instance : has_coe_to_fun (alternating_map R M N ι) (λ _, (ι → M) → N) := ⟨λ x, x.to_fun⟩ initialize_simps_projections alternating_map (to_fun → apply) @[simp] lemma to_fun_eq_coe : f.to_fun = f := rfl @[simp] lemma coe_mk (f : (ι → M) → N) (h₁ h₂ h₃) : ⇑(⟨f, h₁, h₂, h₃⟩ : alternating_map R M N ι) = f := rfl theorem congr_fun {f g : alternating_map R M N ι} (h : f = g) (x : ι → M) : f x = g x := congr_arg (λ h : alternating_map R M N ι, h x) h theorem congr_arg (f : alternating_map R M N ι) {x y : ι → M} (h : x = y) : f x = f y := congr_arg (λ x : ι → M, f x) h theorem coe_injective : injective (coe_fn : alternating_map R M N ι → ((ι → M) → N)) := λ f g h, by { cases f, cases g, cases h, refl } @[simp, norm_cast] theorem coe_inj {f g : alternating_map R M N ι} : (f : (ι → M) → N) = g ↔ f = g := coe_injective.eq_iff @[ext] theorem ext {f f' : alternating_map R M N ι} (H : ∀ x, f x = f' x) : f = f' := coe_injective (funext H) theorem ext_iff {f g : alternating_map R M N ι} : f = g ↔ ∀ x, f x = g x := ⟨λ h x, h ▸ rfl, λ h, ext h⟩ instance : has_coe (alternating_map R M N ι) (multilinear_map R (λ i : ι, M) N) := ⟨λ x, x.to_multilinear_map⟩ @[simp, norm_cast] lemma coe_multilinear_map : ⇑(f : multilinear_map R (λ i : ι, M) N) = f := rfl lemma coe_multilinear_map_injective : function.injective (coe : alternating_map R M N ι → multilinear_map R (λ i : ι, M) N) := λ x y h, ext $ multilinear_map.congr_fun h @[simp] lemma to_multilinear_map_eq_coe : f.to_multilinear_map = f := rfl @[simp] lemma coe_multilinear_map_mk (f : (ι → M) → N) (h₁ h₂ h₃) : ((⟨f, h₁, h₂, h₃⟩ : alternating_map R M N ι) : multilinear_map R (λ i : ι, M) N) = ⟨f, h₁, h₂⟩ := rfl end coercions /-! ### Simp-normal forms of the structure fields These are expressed in terms of `⇑f` instead of `f.to_fun`. -/ @[simp] lemma map_add (i : ι) (x y : M) : f (update v i (x + y)) = f (update v i x) + f (update v i y) := f.to_multilinear_map.map_add' v i x y @[simp] lemma map_sub (i : ι) (x y : M') : g' (update v' i (x - y)) = g' (update v' i x) - g' (update v' i y) := g'.to_multilinear_map.map_sub v' i x y @[simp] lemma map_neg (i : ι) (x : M') : g' (update v' i (-x)) = -g' (update v' i x) := g'.to_multilinear_map.map_neg v' i x @[simp] lemma map_smul (i : ι) (r : R) (x : M) : f (update v i (r • x)) = r • f (update v i x) := f.to_multilinear_map.map_smul' v i r x @[simp] lemma map_eq_zero_of_eq (v : ι → M) {i j : ι} (h : v i = v j) (hij : i ≠ j) : f v = 0 := f.map_eq_zero_of_eq' v i j h hij lemma map_coord_zero {m : ι → M} (i : ι) (h : m i = 0) : f m = 0 := f.to_multilinear_map.map_coord_zero i h @[simp] lemma map_update_zero (m : ι → M) (i : ι) : f (update m i 0) = 0 := f.to_multilinear_map.map_update_zero m i @[simp] lemma map_zero [nonempty ι] : f 0 = 0 := f.to_multilinear_map.map_zero lemma map_eq_zero_of_not_injective (v : ι → M) (hv : ¬function.injective v) : f v = 0 := begin rw function.injective at hv, push_neg at hv, rcases hv with ⟨i₁, i₂, heq, hne⟩, exact f.map_eq_zero_of_eq v heq hne end /-! ### Algebraic structure inherited from `multilinear_map` `alternating_map` carries the same `add_comm_monoid`, `add_comm_group`, and `module` structure as `multilinear_map` -/ section has_scalar variables {S : Type*} [monoid S] [distrib_mul_action S N] [smul_comm_class R S N] instance : has_scalar S (alternating_map R M N ι) := ⟨λ c f, { map_eq_zero_of_eq' := λ v i j h hij, by simp [f.map_eq_zero_of_eq v h hij], ..((c • f : multilinear_map R (λ i : ι, M) N)) }⟩ @[simp] lemma smul_apply (c : S) (m : ι → M) : (c • f) m = c • f m := rfl @[norm_cast] lemma coe_smul (c : S): ((c • f : alternating_map R M N ι) : multilinear_map R (λ i : ι, M) N) = c • f := rfl lemma coe_fn_smul (c : S) (f : alternating_map R M N ι) : ⇑(c • f) = c • f := rfl end has_scalar instance : has_add (alternating_map R M N ι) := ⟨λ a b, { map_eq_zero_of_eq' := λ v i j h hij, by simp [a.map_eq_zero_of_eq v h hij, b.map_eq_zero_of_eq v h hij], ..(a + b : multilinear_map R (λ i : ι, M) N)}⟩ @[simp] lemma add_apply : (f + f') v = f v + f' v := rfl @[norm_cast] lemma coe_add : (↑(f + f') : multilinear_map R (λ i : ι, M) N) = f + f' := rfl instance : has_zero (alternating_map R M N ι) := ⟨{map_eq_zero_of_eq' := λ v i j h hij, by simp, ..(0 : multilinear_map R (λ i : ι, M) N)}⟩ @[simp] lemma zero_apply : (0 : alternating_map R M N ι) v = 0 := rfl @[norm_cast] lemma coe_zero : ((0 : alternating_map R M N ι) : multilinear_map R (λ i : ι, M) N) = 0 := rfl instance : inhabited (alternating_map R M N ι) := ⟨0⟩ instance : add_comm_monoid (alternating_map R M N ι) := coe_injective.add_comm_monoid _ rfl (λ _ _, rfl) (λ _ _, coe_fn_smul _ _) instance : has_neg (alternating_map R M N' ι) := ⟨λ f, { map_eq_zero_of_eq' := λ v i j h hij, by simp [f.map_eq_zero_of_eq v h hij], ..(-(f : multilinear_map R (λ i : ι, M) N')) }⟩ @[simp] lemma neg_apply (m : ι → M) : (-g) m = -(g m) := rfl @[norm_cast] lemma coe_neg : ((-g : alternating_map R M N' ι) : multilinear_map R (λ i : ι, M) N') = -g := rfl instance : has_sub (alternating_map R M N' ι) := ⟨λ f g, { map_eq_zero_of_eq' := λ v i j h hij, by simp [f.map_eq_zero_of_eq v h hij, g.map_eq_zero_of_eq v h hij], ..(f - g : multilinear_map R (λ i : ι, M) N') }⟩ @[simp] lemma sub_apply (m : ι → M) : (g - g₂) m = g m - g₂ m := rfl @[norm_cast] lemma coe_sub : (↑(g - g₂) : multilinear_map R (λ i : ι, M) N') = g - g₂ := rfl instance : add_comm_group (alternating_map R M N' ι) := coe_injective.add_comm_group _ rfl (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl) (λ _ _, coe_fn_smul _ _) (λ _ _, coe_fn_smul _ _) section distrib_mul_action variables {S : Type*} [monoid S] [distrib_mul_action S N] [smul_comm_class R S N] instance : distrib_mul_action S (alternating_map R M N ι) := { one_smul := λ f, ext $ λ x, one_smul _ _, mul_smul := λ c₁ c₂ f, ext $ λ x, mul_smul _ _ _, smul_zero := λ r, ext $ λ x, smul_zero _, smul_add := λ r f₁ f₂, ext $ λ x, smul_add _ _ _ } end distrib_mul_action section module variables {S : Type*} [semiring S] [module S N] [smul_comm_class R S N] /-- The space of multilinear maps over an algebra over `R` is a module over `R`, for the pointwise addition and scalar multiplication. -/ instance : module S (alternating_map R M N ι) := { add_smul := λ r₁ r₂ f, ext $ λ x, add_smul _ _ _, zero_smul := λ f, ext $ λ x, zero_smul _ _ } instance [no_zero_smul_divisors S N] : no_zero_smul_divisors S (alternating_map R M N ι) := coe_injective.no_zero_smul_divisors _ rfl coe_fn_smul end module section variables (R N) /-- The evaluation map from `ι → N` to `N` at a given `i` is alternating when `ι` is subsingleton. -/ @[simps] def of_subsingleton [subsingleton ι] (i : ι) : alternating_map R N N ι := { to_fun := function.eval i, map_eq_zero_of_eq' := λ v i j hv hij, (hij $ subsingleton.elim _ _).elim, ..multilinear_map.of_subsingleton R N i } end end alternating_map /-! ### Composition with linear maps -/ namespace linear_map variables {N₂ : Type*} [add_comm_monoid N₂] [module R N₂] /-- Composing a alternating map with a linear map on the left gives again an alternating map. -/ def comp_alternating_map (g : N →ₗ[R] N₂) : alternating_map R M N ι →+ alternating_map R M N₂ ι := { to_fun := λ f, { map_eq_zero_of_eq' := λ v i j h hij, by simp [f.map_eq_zero_of_eq v h hij], ..(g.comp_multilinear_map (f : multilinear_map R (λ _ : ι, M) N)) }, map_zero' := by { ext, simp }, map_add' := λ a b, by { ext, simp } } @[simp] lemma coe_comp_alternating_map (g : N →ₗ[R] N₂) (f : alternating_map R M N ι) : ⇑(g.comp_alternating_map f) = g ∘ f := rfl lemma comp_alternating_map_apply (g : N →ₗ[R] N₂) (f : alternating_map R M N ι) (m : ι → M) : g.comp_alternating_map f m = g (f m) := rfl end linear_map namespace alternating_map variables {M₂ : Type*} [add_comm_monoid M₂] [module R M₂] variables {M₃ : Type*} [add_comm_monoid M₃] [module R M₃] /-- Composing a alternating map with the same linear map on each argument gives again an alternating map. -/ def comp_linear_map (f : alternating_map R M N ι) (g : M₂ →ₗ[R] M) : alternating_map R M₂ N ι := { map_eq_zero_of_eq' := λ v i j h hij, f.map_eq_zero_of_eq _ (linear_map.congr_arg h) hij, .. (f : multilinear_map R (λ _ : ι, M) N).comp_linear_map (λ _, g) } lemma coe_comp_linear_map (f : alternating_map R M N ι) (g : M₂ →ₗ[R] M) : ⇑(f.comp_linear_map g) = f ∘ ((∘) g) := rfl @[simp] lemma comp_linear_map_apply (f : alternating_map R M N ι) (g : M₂ →ₗ[R] M) (v : ι → M₂) : f.comp_linear_map g v = f (λ i, g (v i)) := rfl /-- Composing an alternating map twice with the same linear map in each argument is the same as composing with their composition. -/ lemma comp_linear_map_assoc (f : alternating_map R M N ι) (g₁ : M₂ →ₗ[R] M) (g₂ : M₃ →ₗ[R] M₂) : (f.comp_linear_map g₁).comp_linear_map g₂ = f.comp_linear_map (g₁ ∘ₗ g₂) := rfl @[simp] lemma zero_comp_linear_map (g : M₂ →ₗ[R] M) : (0 : alternating_map R M N ι).comp_linear_map g = 0 := by { ext, simp only [comp_linear_map_apply, zero_apply] } @[simp] lemma add_comp_linear_map (f₁ f₂ : alternating_map R M N ι) (g : M₂ →ₗ[R] M) : (f₁ + f₂).comp_linear_map g = f₁.comp_linear_map g + f₂.comp_linear_map g := by { ext, simp only [comp_linear_map_apply, add_apply] } @[simp] lemma comp_linear_map_zero [nonempty ι] (f : alternating_map R M N ι) : f.comp_linear_map (0 : M₂ →ₗ[R] M) = 0 := begin ext, simp_rw [comp_linear_map_apply, linear_map.zero_apply, ←pi.zero_def, map_zero, zero_apply], end /-- Composing an alternating map with the identity linear map in each argument. -/ @[simp] lemma comp_linear_map_id (f : alternating_map R M N ι) : f.comp_linear_map linear_map.id = f := ext $ λ _, rfl /-- Composing with a surjective linear map is injective. -/ lemma comp_linear_map_injective (f : M₂ →ₗ[R] M) (hf : function.surjective f) : function.injective (λ g : alternating_map R M N ι, g.comp_linear_map f) := λ g₁ g₂ h, ext $ λ x, by simpa [function.surj_inv_eq hf] using ext_iff.mp h (function.surj_inv hf ∘ x) lemma comp_linear_map_inj (f : M₂ →ₗ[R] M) (hf : function.surjective f) (g₁ g₂ : alternating_map R M N ι) : g₁.comp_linear_map f = g₂.comp_linear_map f ↔ g₁ = g₂ := (comp_linear_map_injective _ hf).eq_iff section dom_lcongr variables (ι R N) (S : Type*) [semiring S] [module S N] [smul_comm_class R S N] /-- Construct a linear equivalence between maps from a linear equivalence between domains. -/ @[simps apply] def dom_lcongr (e : M ≃ₗ[R] M₂) : alternating_map R M N ι ≃ₗ[S] alternating_map R M₂ N ι := { to_fun := λ f, f.comp_linear_map e.symm, inv_fun := λ g, g.comp_linear_map e, map_add' := λ _ _, rfl, map_smul' := λ _ _, rfl, left_inv := λ f, alternating_map.ext $ λ v, f.congr_arg $ funext $ λ i, e.symm_apply_apply _, right_inv := λ f, alternating_map.ext $ λ v, f.congr_arg $ funext $ λ i, e.apply_symm_apply _ } @[simp] lemma dom_lcongr_refl : dom_lcongr R N ι S (linear_equiv.refl R M) = linear_equiv.refl S _ := linear_equiv.ext $ λ _, alternating_map.ext $ λ v, rfl @[simp] lemma dom_lcongr_symm (e : M ≃ₗ[R] M₂) : (dom_lcongr R N ι S e).symm = dom_lcongr R N ι S e.symm := rfl lemma dom_lcongr_trans (e : M ≃ₗ[R] M₂) (f : M₂ ≃ₗ[R] M₃): (dom_lcongr R N ι S e).trans (dom_lcongr R N ι S f) = dom_lcongr R N ι S (e.trans f) := rfl end dom_lcongr /-- Composing an alternating map with the same linear equiv on each argument gives the zero map if and only if the alternating map is the zero map. -/ @[simp] lemma comp_linear_equiv_eq_zero_iff (f : alternating_map R M N ι) (g : M₂ ≃ₗ[R] M) : f.comp_linear_map (g : M₂ →ₗ[R] M) = 0 ↔ f = 0 := (dom_lcongr R N ι ℕ g.symm).map_eq_zero_iff variables (f f' : alternating_map R M N ι) variables (g g₂ : alternating_map R M N' ι) variables (g' : alternating_map R M' N' ι) variables (v : ι → M) (v' : ι → M') open function /-! ### Other lemmas from `multilinear_map` -/ section open_locale big_operators lemma map_update_sum {α : Type*} (t : finset α) (i : ι) (g : α → M) (m : ι → M): f (update m i (∑ a in t, g a)) = ∑ a in t, f (update m i (g a)) := f.to_multilinear_map.map_update_sum t i g m end /-! ### Theorems specific to alternating maps Various properties of reordered and repeated inputs which follow from `alternating_map.map_eq_zero_of_eq`. -/ lemma map_update_self {i j : ι} (hij : i ≠ j) : f (function.update v i (v j)) = 0 := f.map_eq_zero_of_eq _ (by rw [function.update_same, function.update_noteq hij.symm]) hij lemma map_update_update {i j : ι} (hij : i ≠ j) (m : M) : f (function.update (function.update v i m) j m) = 0 := f.map_eq_zero_of_eq _ (by rw [function.update_same, function.update_noteq hij, function.update_same]) hij lemma map_swap_add {i j : ι} (hij : i ≠ j) : f (v ∘ equiv.swap i j) + f v = 0 := begin rw equiv.comp_swap_eq_update, convert f.map_update_update v hij (v i + v j), simp [f.map_update_self _ hij, f.map_update_self _ hij.symm, function.update_comm hij (v i + v j) (v _) v, function.update_comm hij.symm (v i) (v i) v], end lemma map_add_swap {i j : ι} (hij : i ≠ j) : f v + f (v ∘ equiv.swap i j) = 0 := by { rw add_comm, exact f.map_swap_add v hij } lemma map_swap {i j : ι} (hij : i ≠ j) : g (v ∘ equiv.swap i j) = - g v := eq_neg_of_add_eq_zero_left $ g.map_swap_add v hij lemma map_perm [fintype ι] (v : ι → M) (σ : equiv.perm ι) : g (v ∘ σ) = σ.sign • g v := begin apply equiv.perm.swap_induction_on' σ, { simp }, { intros s x y hxy hI, simpa [g.map_swap (v ∘ s) hxy, equiv.perm.sign_swap hxy] using hI, } end lemma map_congr_perm [fintype ι] (σ : equiv.perm ι) : g v = σ.sign • g (v ∘ σ) := by { rw [g.map_perm, smul_smul], simp } lemma coe_dom_dom_congr [fintype ι] (σ : equiv.perm ι) : (g : multilinear_map R (λ _ : ι, M) N').dom_dom_congr σ = σ.sign • (g : multilinear_map R (λ _ : ι, M) N') := multilinear_map.ext $ λ v, g.map_perm v σ /-- If the arguments are linearly dependent then the result is `0`. -/ lemma map_linear_dependent {K : Type*} [ring K] {M : Type*} [add_comm_group M] [module K M] {N : Type*} [add_comm_group N] [module K N] [no_zero_smul_divisors K N] (f : alternating_map K M N ι) (v : ι → M) (h : ¬linear_independent K v) : f v = 0 := begin obtain ⟨s, g, h, i, hi, hz⟩ := not_linear_independent_iff.mp h, suffices : f (update v i (g i • v i)) = 0, { rw [f.map_smul, function.update_eq_self, smul_eq_zero] at this, exact or.resolve_left this hz, }, conv at h in (g _ • v _) { rw ←if_t_t (i = x) (g _ • v _), }, rw [finset.sum_ite, finset.filter_eq, finset.filter_ne, if_pos hi, finset.sum_singleton, add_eq_zero_iff_eq_neg] at h, rw [h, f.map_neg, f.map_update_sum, neg_eq_zero, finset.sum_eq_zero], intros j hj, obtain ⟨hij, _⟩ := finset.mem_erase.mp hj, rw [f.map_smul, f.map_update_self _ hij.symm, smul_zero], end end alternating_map open_locale big_operators namespace multilinear_map open equiv variables [fintype ι] private lemma alternization_map_eq_zero_of_eq_aux (m : multilinear_map R (λ i : ι, M) N') (v : ι → M) (i j : ι) (i_ne_j : i ≠ j) (hv : v i = v j) : (∑ (σ : perm ι), σ.sign • m.dom_dom_congr σ) v = 0 := begin rw sum_apply, exact finset.sum_involution (λ σ _, swap i j * σ) (λ σ _, by simp [perm.sign_swap i_ne_j, apply_swap_eq_self hv]) (λ σ _ _, (not_congr swap_mul_eq_iff).mpr i_ne_j) (λ σ _, finset.mem_univ _) (λ σ _, swap_mul_involutive i j σ) end /-- Produce an `alternating_map` out of a `multilinear_map`, by summing over all argument permutations. -/ def alternatization : multilinear_map R (λ i : ι, M) N' →+ alternating_map R M N' ι := { to_fun := λ m, { to_fun := ⇑(∑ (σ : perm ι), σ.sign • m.dom_dom_congr σ), map_eq_zero_of_eq' := λ v i j hvij hij, alternization_map_eq_zero_of_eq_aux m v i j hij hvij, .. (∑ (σ : perm ι), σ.sign • m.dom_dom_congr σ)}, map_add' := λ a b, begin ext, simp only [ finset.sum_add_distrib, smul_add, add_apply, dom_dom_congr_apply, alternating_map.add_apply, alternating_map.coe_mk, smul_apply, sum_apply], end, map_zero' := begin ext, simp only [ finset.sum_const_zero, smul_zero, zero_apply, dom_dom_congr_apply, alternating_map.zero_apply, alternating_map.coe_mk, smul_apply, sum_apply], end } lemma alternatization_def (m : multilinear_map R (λ i : ι, M) N') : ⇑(alternatization m) = (∑ (σ : perm ι), σ.sign • m.dom_dom_congr σ : _) := rfl lemma alternatization_coe (m : multilinear_map R (λ i : ι, M) N') : ↑m.alternatization = (∑ (σ : perm ι), σ.sign • m.dom_dom_congr σ : _) := coe_injective rfl lemma alternatization_apply (m : multilinear_map R (λ i : ι, M) N') (v : ι → M) : alternatization m v = ∑ (σ : perm ι), σ.sign • m.dom_dom_congr σ v := by simp only [alternatization_def, smul_apply, sum_apply] end multilinear_map namespace alternating_map /-- Alternatizing a multilinear map that is already alternating results in a scale factor of `n!`, where `n` is the number of inputs. -/ lemma coe_alternatization [fintype ι] (a : alternating_map R M N' ι) : (↑a : multilinear_map R (λ ι, M) N').alternatization = nat.factorial (fintype.card ι) • a := begin apply alternating_map.coe_injective, simp_rw [multilinear_map.alternatization_def, coe_dom_dom_congr, smul_smul, int.units_mul_self, one_smul, finset.sum_const, finset.card_univ, fintype.card_perm, ←coe_multilinear_map, coe_smul], end end alternating_map namespace linear_map variables {N'₂ : Type*} [add_comm_group N'₂] [module R N'₂] [fintype ι] /-- Composition with a linear map before and after alternatization are equivalent. -/ lemma comp_multilinear_map_alternatization (g : N' →ₗ[R] N'₂) (f : multilinear_map R (λ _ : ι, M) N') : (g.comp_multilinear_map f).alternatization = g.comp_alternating_map (f.alternatization) := by { ext, simp [multilinear_map.alternatization_def] } end linear_map section coprod open_locale big_operators open_locale tensor_product variables {ιa ιb : Type*} [decidable_eq ιa] [decidable_eq ιb] [fintype ιa] [fintype ιb] variables {R' : Type*} {Mᵢ N₁ N₂ : Type*} [comm_semiring R'] [add_comm_group N₁] [module R' N₁] [add_comm_group N₂] [module R' N₂] [add_comm_monoid Mᵢ] [module R' Mᵢ] namespace equiv.perm /-- Elements which are considered equivalent if they differ only by swaps within α or β -/ abbreviation mod_sum_congr (α β : Type*) := _ ⧸ (equiv.perm.sum_congr_hom α β).range lemma mod_sum_congr.swap_smul_involutive {α β : Type*} [decidable_eq (α ⊕ β)] (i j : α ⊕ β) : function.involutive (has_scalar.smul (equiv.swap i j) : mod_sum_congr α β → mod_sum_congr α β) := λ σ, begin apply σ.induction_on' (λ σ, _), exact _root_.congr_arg quotient.mk' (equiv.swap_mul_involutive i j σ) end end equiv.perm namespace alternating_map open equiv /-- summand used in `alternating_map.dom_coprod` -/ def dom_coprod.summand (a : alternating_map R' Mᵢ N₁ ιa) (b : alternating_map R' Mᵢ N₂ ιb) (σ : perm.mod_sum_congr ιa ιb) : multilinear_map R' (λ _ : ιa ⊕ ιb, Mᵢ) (N₁ ⊗[R'] N₂) := quotient.lift_on' σ (λ σ, σ.sign • (multilinear_map.dom_coprod ↑a ↑b : multilinear_map R' (λ _, Mᵢ) (N₁ ⊗ N₂)).dom_dom_congr σ) (λ σ₁ σ₂ ⟨⟨sl, sr⟩, h⟩, begin ext v, simp only [multilinear_map.dom_dom_congr_apply, multilinear_map.dom_coprod_apply, coe_multilinear_map, multilinear_map.smul_apply], replace h := inv_mul_eq_iff_eq_mul.mp h.symm, have : (σ₁ * perm.sum_congr_hom _ _ (sl, sr)).sign = σ₁.sign * (sl.sign * sr.sign) := by simp, rw [h, this, mul_smul, mul_smul, smul_left_cancel_iff, ←tensor_product.tmul_smul, tensor_product.smul_tmul'], simp only [sum.map_inr, perm.sum_congr_hom_apply, perm.sum_congr_apply, sum.map_inl, function.comp_app, perm.coe_mul], rw [←a.map_congr_perm (λ i, v (σ₁ _)), ←b.map_congr_perm (λ i, v (σ₁ _))], end) lemma dom_coprod.summand_mk' (a : alternating_map R' Mᵢ N₁ ιa) (b : alternating_map R' Mᵢ N₂ ιb) (σ : equiv.perm (ιa ⊕ ιb)) : dom_coprod.summand a b (quotient.mk' σ) = σ.sign • (multilinear_map.dom_coprod ↑a ↑b : multilinear_map R' (λ _, Mᵢ) (N₁ ⊗ N₂)).dom_dom_congr σ := rfl /-- Swapping elements in `σ` with equal values in `v` results in an addition that cancels -/ lemma dom_coprod.summand_add_swap_smul_eq_zero (a : alternating_map R' Mᵢ N₁ ιa) (b : alternating_map R' Mᵢ N₂ ιb) (σ : perm.mod_sum_congr ιa ιb) {v : ιa ⊕ ιb → Mᵢ} {i j : ιa ⊕ ιb} (hv : v i = v j) (hij : i ≠ j) : dom_coprod.summand a b σ v + dom_coprod.summand a b (swap i j • σ) v = 0 := begin apply σ.induction_on' (λ σ, _), dsimp only [quotient.lift_on'_mk', quotient.map'_mk', mul_action.quotient.smul_mk, dom_coprod.summand], rw [smul_eq_mul, perm.sign_mul, perm.sign_swap hij], simp only [one_mul, neg_mul, function.comp_app, units.neg_smul, perm.coe_mul, units.coe_neg, multilinear_map.smul_apply, multilinear_map.neg_apply, multilinear_map.dom_dom_congr_apply, multilinear_map.dom_coprod_apply], convert add_right_neg _; { ext k, rw equiv.apply_swap_eq_self hv }, end /-- Swapping elements in `σ` with equal values in `v` result in zero if the swap has no effect on the quotient. -/ lemma dom_coprod.summand_eq_zero_of_smul_invariant (a : alternating_map R' Mᵢ N₁ ιa) (b : alternating_map R' Mᵢ N₂ ιb) (σ : perm.mod_sum_congr ιa ιb) {v : ιa ⊕ ιb → Mᵢ} {i j : ιa ⊕ ιb} (hv : v i = v j) (hij : i ≠ j) : swap i j • σ = σ → dom_coprod.summand a b σ v = 0 := begin apply σ.induction_on' (λ σ, _), dsimp only [quotient.lift_on'_mk', quotient.map'_mk', multilinear_map.smul_apply, multilinear_map.dom_dom_congr_apply, multilinear_map.dom_coprod_apply, dom_coprod.summand], intro hσ, with_cases { cases hi : σ⁻¹ i; cases hj : σ⁻¹ j; rw perm.inv_eq_iff_eq at hi hj; substs hi hj, }, case [sum.inl sum.inr : i' j', sum.inr sum.inl : i' j'] { -- the term pairs with and cancels another term all_goals { obtain ⟨⟨sl, sr⟩, hσ⟩ := quotient.exact' hσ, }, work_on_goal 1 { replace hσ := equiv.congr_fun hσ (sum.inl i'), }, work_on_goal 2 { replace hσ := equiv.congr_fun hσ (sum.inr i'), }, all_goals { rw [smul_eq_mul, ←mul_swap_eq_swap_mul, mul_inv_rev, swap_inv, inv_mul_cancel_right] at hσ, simpa using hσ, }, }, case [sum.inr sum.inr : i' j', sum.inl sum.inl : i' j'] { -- the term does not pair but is zero all_goals { convert smul_zero _, }, work_on_goal 1 { convert tensor_product.tmul_zero _ _, }, work_on_goal 2 { convert tensor_product.zero_tmul _ _, }, all_goals { exact alternating_map.map_eq_zero_of_eq _ _ hv (λ hij', hij (hij' ▸ rfl)), } }, end /-- Like `multilinear_map.dom_coprod`, but ensures the result is also alternating. Note that this is usually defined (for instance, as used in Proposition 22.24 in [Gallier2011Notes]) over integer indices `ιa = fin n` and `ιb = fin m`, as $$ (f \wedge g)(u_1, \ldots, u_{m+n}) = \sum_{\operatorname{shuffle}(m, n)} \operatorname{sign}(\sigma) f(u_{\sigma(1)}, \ldots, u_{\sigma(m)}) g(u_{\sigma(m+1)}, \ldots, u_{\sigma(m+n)}), $$ where $\operatorname{shuffle}(m, n)$ consists of all permutations of $[1, m+n]$ such that $\sigma(1) < \cdots < \sigma(m)$ and $\sigma(m+1) < \cdots < \sigma(m+n)$. Here, we generalize this by replacing: * the product in the sum with a tensor product * the filtering of $[1, m+n]$ to shuffles with an isomorphic quotient * the additions in the subscripts of $\sigma$ with an index of type `sum` The specialized version can be obtained by combining this definition with `fin_sum_fin_equiv` and `algebra.lmul'`. -/ @[simps] def dom_coprod (a : alternating_map R' Mᵢ N₁ ιa) (b : alternating_map R' Mᵢ N₂ ιb) : alternating_map R' Mᵢ (N₁ ⊗[R'] N₂) (ιa ⊕ ιb) := { to_fun := λ v, ⇑(∑ σ : perm.mod_sum_congr ιa ιb, dom_coprod.summand a b σ) v, map_eq_zero_of_eq' := λ v i j hv hij, begin dsimp only, rw multilinear_map.sum_apply, exact finset.sum_involution (λ σ _, equiv.swap i j • σ) (λ σ _, dom_coprod.summand_add_swap_smul_eq_zero a b σ hv hij) (λ σ _, mt $ dom_coprod.summand_eq_zero_of_smul_invariant a b σ hv hij) (λ σ _, finset.mem_univ _) (λ σ _, equiv.perm.mod_sum_congr.swap_smul_involutive i j σ), end, ..(∑ σ : perm.mod_sum_congr ιa ιb, dom_coprod.summand a b σ) } lemma dom_coprod_coe (a : alternating_map R' Mᵢ N₁ ιa) (b : alternating_map R' Mᵢ N₂ ιb) : (↑(a.dom_coprod b) : multilinear_map R' (λ _, Mᵢ) _) = ∑ σ : perm.mod_sum_congr ιa ιb, dom_coprod.summand a b σ := multilinear_map.ext $ λ _, rfl /-- A more bundled version of `alternating_map.dom_coprod` that maps `((ι₁ → N) → N₁) ⊗ ((ι₂ → N) → N₂)` to `(ι₁ ⊕ ι₂ → N) → N₁ ⊗ N₂`. -/ def dom_coprod' : (alternating_map R' Mᵢ N₁ ιa ⊗[R'] alternating_map R' Mᵢ N₂ ιb) →ₗ[R'] alternating_map R' Mᵢ (N₁ ⊗[R'] N₂) (ιa ⊕ ιb) := tensor_product.lift $ by refine linear_map.mk₂ R' (dom_coprod) (λ m₁ m₂ n, _) (λ c m n, _) (λ m n₁ n₂, _) (λ c m n, _); { ext, simp only [dom_coprod_apply, add_apply, smul_apply, ←finset.sum_add_distrib, finset.smul_sum, multilinear_map.sum_apply, dom_coprod.summand], congr, ext σ, apply σ.induction_on' (λ σ, _), simp only [quotient.lift_on'_mk', coe_add, coe_smul, multilinear_map.smul_apply, ←multilinear_map.dom_coprod'_apply], simp only [tensor_product.add_tmul, ←tensor_product.smul_tmul', tensor_product.tmul_add, tensor_product.tmul_smul, linear_map.map_add, linear_map.map_smul], rw ←smul_add <|> rw smul_comm, congr } @[simp] lemma dom_coprod'_apply (a : alternating_map R' Mᵢ N₁ ιa) (b : alternating_map R' Mᵢ N₂ ιb) : dom_coprod' (a ⊗ₜ[R'] b) = dom_coprod a b := by simp only [dom_coprod', tensor_product.lift.tmul, linear_map.mk₂_apply] end alternating_map open equiv /-- A helper lemma for `multilinear_map.dom_coprod_alternization`. -/ lemma multilinear_map.dom_coprod_alternization_coe (a : multilinear_map R' (λ _ : ιa, Mᵢ) N₁) (b : multilinear_map R' (λ _ : ιb, Mᵢ) N₂) : multilinear_map.dom_coprod ↑a.alternatization ↑b.alternatization = ∑ (σa : perm ιa) (σb : perm ιb), σa.sign • σb.sign • multilinear_map.dom_coprod (a.dom_dom_congr σa) (b.dom_dom_congr σb) := begin simp_rw [←multilinear_map.dom_coprod'_apply, multilinear_map.alternatization_coe], simp_rw [tensor_product.sum_tmul, tensor_product.tmul_sum, linear_map.map_sum, ←tensor_product.smul_tmul', tensor_product.tmul_smul, linear_map.map_smul_of_tower], end open alternating_map /-- Computing the `multilinear_map.alternatization` of the `multilinear_map.dom_coprod` is the same as computing the `alternating_map.dom_coprod` of the `multilinear_map.alternatization`s. -/ lemma multilinear_map.dom_coprod_alternization (a : multilinear_map R' (λ _ : ιa, Mᵢ) N₁) (b : multilinear_map R' (λ _ : ιb, Mᵢ) N₂) : (multilinear_map.dom_coprod a b).alternatization = a.alternatization.dom_coprod b.alternatization := begin apply coe_multilinear_map_injective, rw [dom_coprod_coe, multilinear_map.alternatization_coe, finset.sum_partition (quotient_group.left_rel (perm.sum_congr_hom ιa ιb).range)], congr' 1, ext1 σ, apply σ.induction_on' (λ σ, _), -- unfold the quotient mess left by `finset.sum_partition` conv in (_ = quotient.mk' _) { change quotient.mk' _ = quotient.mk' _, rw quotient.eq', rw [quotient_group.left_rel], dsimp only [setoid.r] }, -- eliminate a multiplication have : @finset.univ (perm (ιa ⊕ ιb)) _ = finset.univ.image ((*) σ) := (finset.eq_univ_iff_forall.mpr $ λ a, let ⟨a', ha'⟩ := mul_left_surjective σ a in finset.mem_image.mpr ⟨a', finset.mem_univ _, ha'⟩).symm, rw [this, finset.image_filter], simp only [function.comp, mul_inv_rev, inv_mul_cancel_right, subgroup.inv_mem_iff], simp only [monoid_hom.mem_range], -- needs to be separate from the above `simp only` rw [finset.filter_congr_decidable, finset.univ_filter_exists (perm.sum_congr_hom ιa ιb), finset.sum_image (λ x _ y _ (h : _ = _), mul_right_injective _ h), finset.sum_image (λ x _ y _ (h : _ = _), perm.sum_congr_hom_injective h)], dsimp only, -- now we're ready to clean up the RHS, pulling out the summation rw [dom_coprod.summand_mk', multilinear_map.dom_coprod_alternization_coe, ←finset.sum_product', finset.univ_product_univ, ←multilinear_map.dom_dom_congr_equiv_apply, add_equiv.map_sum, finset.smul_sum], congr' 1, ext1 ⟨al, ar⟩, dsimp only, -- pull out the pair of smuls on the RHS, by rewriting to `_ →ₗ[ℤ] _` and back rw [←add_equiv.coe_to_add_monoid_hom, ←add_monoid_hom.coe_to_int_linear_map, linear_map.map_smul_of_tower, linear_map.map_smul_of_tower, add_monoid_hom.coe_to_int_linear_map, add_equiv.coe_to_add_monoid_hom, multilinear_map.dom_dom_congr_equiv_apply], -- pick up the pieces rw [multilinear_map.dom_dom_congr_mul, perm.sign_mul, perm.sum_congr_hom_apply, multilinear_map.dom_coprod_dom_dom_congr_sum_congr, perm.sign_sum_congr, mul_smul, mul_smul], end /-- Taking the `multilinear_map.alternatization` of the `multilinear_map.dom_coprod` of two `alternating_map`s gives a scaled version of the `alternating_map.coprod` of those maps. -/ lemma multilinear_map.dom_coprod_alternization_eq (a : alternating_map R' Mᵢ N₁ ιa) (b : alternating_map R' Mᵢ N₂ ιb) : (multilinear_map.dom_coprod a b : multilinear_map R' (λ _ : ιa ⊕ ιb, Mᵢ) (N₁ ⊗ N₂)) .alternatization = ((fintype.card ιa).factorial * (fintype.card ιb).factorial) • a.dom_coprod b := begin rw [multilinear_map.dom_coprod_alternization, coe_alternatization, coe_alternatization, mul_smul, ←dom_coprod'_apply, ←dom_coprod'_apply, ←tensor_product.smul_tmul', tensor_product.tmul_smul, linear_map.map_smul_of_tower dom_coprod', linear_map.map_smul_of_tower dom_coprod'], -- typeclass resolution is a little confused here apply_instance, apply_instance, end end coprod section basis open alternating_map variables {ι₁ : Type*} [fintype ι] variables {R' : Type*} {N₁ N₂ : Type*} [comm_semiring R'] [add_comm_monoid N₁] [add_comm_monoid N₂] variables [module R' N₁] [module R' N₂] /-- Two alternating maps indexed by a `fintype` are equal if they are equal when all arguments are distinct basis vectors. -/ lemma basis.ext_alternating {f g : alternating_map R' N₁ N₂ ι} (e : basis ι₁ R' N₁) (h : ∀ v : ι → ι₁, function.injective v → f (λ i, e (v i)) = g (λ i, e (v i))) : f = g := begin refine alternating_map.coe_multilinear_map_injective (basis.ext_multilinear e $ λ v, _), by_cases hi : function.injective v, { exact h v hi }, { have : ¬function.injective (λ i, e (v i)) := hi.imp function.injective.of_comp, rw [coe_multilinear_map, coe_multilinear_map, f.map_eq_zero_of_not_injective _ this, g.map_eq_zero_of_not_injective _ this], } end end basis
e54435744bdb86c72678d4590d8c04911b148796
492a7e27d49633a89f7ce6e1e28f676b062fcbc9
/src/monoidal_categories_reboot/pseudo_natural_transformation.lean
a61aa85d55fec4bc63efc4042b53c0cdbfce633e
[ "Apache-2.0" ]
permissive
semorrison/monoidal-categories-reboot
9edba30277de48a234b63813cf85b171772ce36f
48b5f1d535daba4e591672042a298ac36be2e6dd
refs/heads/master
1,642,472,396,149
1,560,587,477,000
1,560,587,477,000
156,465,626
0
1
null
1,541,549,278,000
1,541,549,278,000
null
UTF-8
Lean
false
false
10,180
lean
import .monoidal_functor import .endofunctors import tactic.interactive open category_theory open tactic universes v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ open category_theory.category namespace category_theory variables {C : Type u₁} [𝒞 : monoidal_category.{v₁} C] {D : Type u₂} [𝒟 : monoidal_category.{v₂} D] variables (F G : monoidal_functor.{v₁ v₂} C D) open monoidal_category structure pseudo_natural_transformation := (N : D) (β : Π X : C, (F.obj X) ⊗ N ⟶ N ⊗ (G.obj X)) (β_natural' : Π {X X' : C} (f : X ⟶ X'), (F.map f ⊗ 𝟙 N) ≫ β X' = β X ≫ (𝟙 N ⊗ G.map f) . obviously) (c' : Π X Y : C, β (X ⊗ Y) = ((inv (F.μ X Y)) ⊗ 𝟙 N) ≫ (associator _ _ _).hom ≫ (𝟙 _ ⊗ (β Y)) ≫ (associator _ _ _).inv ≫ ((β X) ⊗ 𝟙 _) ≫ (associator _ _ _).hom ≫ (𝟙 N ⊗ (G.μ X Y)) . obviously) restate_axiom pseudo_natural_transformation.β_natural' attribute [simp,search] pseudo_natural_transformation.β_natural restate_axiom pseudo_natural_transformation.c' attribute [simp,search] pseudo_natural_transformation.c namespace pseudo_natural_transformation def id : pseudo_natural_transformation F F := { N := tensor_unit D, β := λ X, (right_unitor _).hom ≫ (left_unitor _).inv, β_natural' := sorry, c' := sorry } @[simp] lemma id_N : (id F).N = tensor_unit D := rfl variables {F G} def β_nat_trans (σ : pseudo_natural_transformation F G) : F.to_functor ⋙ (tensor_on_right.obj σ.N) ⟶ G.to_functor ⋙ (tensor_on_left.obj σ.N) := { app := λ X, σ.β X, naturality' := λ X Y f, σ.β_natural f } variable {H : monoidal_functor.{v₁ v₂} C D} attribute [trans] nat_trans.vcomp section vcomp variables (σ : pseudo_natural_transformation F G) (τ : pseudo_natural_transformation G H) def vcomp : pseudo_natural_transformation F H := { N := σ.N ⊗ τ.N, β := λ X, (associator _ _ _).inv ≫ (σ.β X ⊗ 𝟙 _) ≫ (associator _ _ _).hom ≫ (𝟙 _ ⊗ τ.β X) ≫ (associator _ _ _).inv, β_natural' := λ X X' f, begin rw ←monoidal_category.tensor_map_id, slice_lhs 1 2 { rw monoidal_category.associator_inv_naturality }, slice_lhs 2 3 { rw [←interchange_left_identity, σ.β_natural, interchange_left_identity], }, slice_lhs 3 4 { rw associator_naturality }, slice_lhs 4 5 { rw [←interchange_right_identity, τ.β_natural, interchange_right_identity], }, repeat { rw category.assoc }, rw monoidal_category.associator_inv_naturality, end, c' := sorry } @[simp] lemma vcomp_N : (σ.vcomp τ).N = σ.N ⊗ τ.N := rfl -- Hopefully this is eventually provable just by `rfl` lemma vcomp_β_nat_trans : (σ.vcomp τ).β_nat_trans = (by calc F.to_functor ⋙ (tensor_on_right).obj (σ.N ⊗ τ.N) ⟶ F.to_functor ⋙ ((tensor_on_right).obj σ.N) ⋙ ((tensor_on_right).obj τ.N) : whisker_left F.to_functor sorry ... ⟶ (F.to_functor ⋙ (tensor_on_right).obj τ.N) ⋙ ((tensor_on_right).obj σ.N) : sorry ... ⟶ (H.to_functor ⋙ (tensor_on_left).obj (σ.N ⊗ τ.N)) : sorry) := sorry end vcomp variables {E : Type u₃} [ℰ : monoidal_category.{v₃} E] variables {K L : monoidal_functor D E} attribute [trans] category.comp section hcomp variables (σ : pseudo_natural_transformation F G) (τ : pseudo_natural_transformation K L) def hcomp : pseudo_natural_transformation (F.comp K) (G.comp L) := { N := (K.obj σ.N) ⊗ τ.N, β := λ X, by calc K.obj (F.obj X) ⊗ K.obj σ.N ⊗ τ.N ⟶ (K.obj (F.obj X) ⊗ K.obj σ.N) ⊗ τ.N : (associator _ _ _).inv ... ⟶ (K.obj ((F.obj X) ⊗ σ.N)) ⊗ τ.N : (K.μ _ _).hom ⊗ 𝟙 _ ... ⟶ (K.obj (σ.N ⊗ (G.obj X))) ⊗ τ.N : K.map (σ.β X) ⊗ 𝟙 _ ... ⟶ (K.obj σ.N ⊗ (K.obj (G.obj X))) ⊗ τ.N : (K.μ _ _).inv ⊗ 𝟙 _ ... ⟶ K.obj σ.N ⊗ (K.obj (G.obj X)) ⊗ τ.N : (associator _ _ _).hom ... ⟶ K.obj σ.N ⊗ (τ.N ⊗ L.obj (G.obj X)) : 𝟙 _ ⊗ τ.β _ ... ⟶ (K.obj σ.N ⊗ τ.N) ⊗ L.obj (G.obj X) : (associator _ _ _).inv, β_natural' := sorry, c' := sorry } @[simp] lemma hcomp_N : (σ.hcomp τ).N = (K.obj σ.N) ⊗ τ.N := rfl end hcomp end pseudo_natural_transformation variables {F G} variables (σ τ : pseudo_natural_transformation F G) structure modification := (hom : σ.N ⟶ τ.N) (w' : Π X : C, σ.β X ≫ (hom ⊗ 𝟙 _) = (𝟙 _ ⊗ hom) ≫ τ.β X . obviously) restate_axiom modification.w' attribute [search] modification.w namespace pseudo_natural_transformation namespace vcomp variables {H K : monoidal_functor C D} variables (ρ : pseudo_natural_transformation G H) (ν : pseudo_natural_transformation H K) def associator_hom : modification ((σ.vcomp ρ).vcomp ν) (σ.vcomp (ρ.vcomp ν)) := { hom := (associator _ _ _).hom, w' := sorry } def associator_inv : modification (σ.vcomp (ρ.vcomp ν)) ((σ.vcomp ρ).vcomp ν) := { hom := (associator _ _ _).inv, w' := sorry } def left_unitor_hom : modification ((pseudo_natural_transformation.id _).vcomp σ) σ := { hom := (left_unitor σ.N).hom, w' := sorry } def left_unitor_inv : modification σ ((pseudo_natural_transformation.id _).vcomp σ) := { hom := (left_unitor σ.N).inv, w' := sorry } def right_unitor_hom : modification (σ.vcomp (pseudo_natural_transformation.id _)) σ := { hom := (right_unitor σ.N).hom, w' := sorry } def right_unitor_inv : modification σ (σ.vcomp (pseudo_natural_transformation.id _)) := { hom := (right_unitor σ.N).inv, w' := sorry } end vcomp section variables {A : Type u₃} [𝒜 : monoidal_category.{v₃} A] variables {B : Type u₄} [ℬ : monoidal_category.{v₄} B] variables {K L : monoidal_functor A B} variables {M N : monoidal_functor B C} variables (ρ : pseudo_natural_transformation K L) variables (ν : pseudo_natural_transformation M N) -- def hcomp_assoc_hom : modification ((ρ.hcomp ν).hcomp σ) (ρ.hcomp (ν.hcomp σ)) end section exchange variables {H : monoidal_functor C D} variables (ρ : pseudo_natural_transformation G H) variables {E : Type u₃} [ℰ : monoidal_category.{v₃} E] variables {K L M : monoidal_functor D E} variables (ν : pseudo_natural_transformation K L) variables (κ : pseudo_natural_transformation L M) def exchange : modification ((σ.vcomp ρ).hcomp (ν.vcomp κ)) ((σ.hcomp ν).vcomp (ρ.hcomp κ)) := { hom := by calc K.obj (σ.N ⊗ ρ.N) ⊗ (ν.N ⊗ κ.N) ⟶ (K.obj σ.N ⊗ K.obj ρ.N) ⊗ (ν.N ⊗ κ.N) : (K.μ _ _).inv ⊗ 𝟙 _ ... ⟶ K.obj σ.N ⊗ (K.obj ρ.N ⊗ ν.N) ⊗ κ.N : sorry ... ⟶ K.obj σ.N ⊗ (ν.N ⊗ L.obj ρ.N) ⊗ κ.N : 𝟙 _ ⊗ (ν.β _) ⊗ 𝟙 _ ... ⟶ (K.obj (σ.N) ⊗ ν.N) ⊗ (L.obj (ρ.N) ⊗ κ.N) : sorry, w' := sorry } end exchange end pseudo_natural_transformation namespace modification @[extensionality] lemma ext {f g : modification σ τ} (p : f.hom = g.hom) : f = g := begin cases f, cases g, congr, exact p end variables (ρ : pseudo_natural_transformation F G) def id : modification σ σ := { hom := 𝟙 _ } @[simp] lemma id_hom : (id σ).hom = 𝟙 _ := rfl variables {σ τ ρ} def comp (f : modification σ τ) (g : modification τ ρ) : modification σ ρ := { hom := f.hom ≫ g.hom }. @[simp] lemma comp_hom (f : modification σ τ) (g : modification τ ρ) : (f.comp g).hom = f.hom ≫ g.hom := rfl end modification instance category_pseudo_natural_transformations : category (pseudo_natural_transformation F G) := { hom := modification, id := modification.id, comp := λ _ _ _ f g, modification.comp f g }. namespace pseudo_natural_transformation @[simp] lemma id_hom (ρ : pseudo_natural_transformation F G) : ((𝟙 ρ) : modification ρ ρ).hom = 𝟙 _ := rfl @[simp] lemma comp_hom {ρ σ τ : pseudo_natural_transformation F G} (f : ρ ⟶ σ) (g : σ ⟶ τ) : (f ≫ g).hom = f.hom ≫ g.hom := rfl end pseudo_natural_transformation namespace pseudo_natural_transformation.vcomp variables {H K : monoidal_functor C D} variables (ρ : pseudo_natural_transformation G H) (ν : pseudo_natural_transformation H K) @[simp] def associator : ((σ.vcomp ρ).vcomp ν) ≅ (σ.vcomp (ρ.vcomp ν)) := { hom := associator_hom _ _ _, inv := associator_inv _ _ _, hom_inv_id' := sorry, inv_hom_id' := sorry } @[simp] def left_unitor : ((pseudo_natural_transformation.id _).vcomp σ) ≅ σ := { hom := left_unitor_hom _, inv := left_unitor_inv _, hom_inv_id' := sorry, inv_hom_id' := sorry } @[simp] def right_unitor : (σ.vcomp (pseudo_natural_transformation.id _)) ≅ σ := { hom := right_unitor_hom _, inv := right_unitor_inv _, hom_inv_id' := sorry, inv_hom_id' := sorry } end pseudo_natural_transformation.vcomp namespace modification open pseudo_natural_transformation variables {σ τ} variables {H : monoidal_functor C D} variables {α β : pseudo_natural_transformation G H} def vcomp (f : modification σ τ) (g : modification α β) : modification (σ.vcomp α) (τ.vcomp β) := { hom := f.hom ⊗ g.hom, w' := by sorry }. @[simp] lemma vcomp_hom (f : modification σ τ) (g : modification α β) : (f.vcomp g).hom = f.hom ⊗ g.hom := rfl instance monoidal_category_pseudo_natural_endotransformations : monoidal_category (pseudo_natural_transformation F F) := { tensor_obj := λ σ τ, σ.vcomp τ, tensor_hom := λ _ _ _ _ f g, f.vcomp g, tensor_unit := pseudo_natural_transformation.id F, associator := λ σ τ ρ, vcomp.associator σ τ ρ, left_unitor := λ σ, vcomp.left_unitor σ, right_unitor := λ σ, vcomp.right_unitor σ }. variables {E : Type u₃} [ℰ : monoidal_category.{u₃ v₃} E] variables {K L : monoidal_functor D E} variables {γ δ : pseudo_natural_transformation K L} def hcomp (f : modification σ τ) (g : modification γ δ) : modification (σ.hcomp γ) (τ.hcomp δ) := { hom := K.map (f.hom) ⊗ g.hom, w' := λ X, begin dsimp [pseudo_natural_transformation.hcomp], simp, slice_rhs 1 2 { rw monoidal_category.associator_inv_naturality }, repeat { rw category.assoc }, apply congr_arg, sorry end }. end modification -- TODO obtain the Drinfeld centre from these, as a braided monoidal category end category_theory
8ed430a8412c565e1683195c779b479f3dceef3a
57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d
/tests/lean/run/structInst3.lean
c43fee28167d704145ba6bec8fd73ecf14263bce
[ "Apache-2.0" ]
permissive
collares/lean4
861a9269c4592bce49b71059e232ff0bfe4594cc
52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee
refs/heads/master
1,691,419,031,324
1,618,678,138,000
1,618,678,138,000
358,989,750
0
0
Apache-2.0
1,618,696,333,000
1,618,696,333,000
null
UTF-8
Lean
false
false
599
lean
universes u namespace Ex1 structure A (α : Type u) := (x : α) (f : α → α := λ x => x) structure B (α : Type u) extends A α := (y : α := f (f x)) (g : α → α → α := λ x y => f x) structure C (α : Type u) extends B α := (z : α := g x y) (x := f z) end Ex1 open Ex1 def c1 : C Nat := { x := 1 } #check { c1 with z := 2 } #check { c1 with z := 2 } theorem ex1 : { c1 with z := 2 }.z = 2 := rfl #check ex1 theorem ex2 : { c1 with z := 2 }.x = c1.x := rfl #check ex2 def c2 : C (Nat × Nat) := { z := (1, 1) } #check { c2 with x.fst := 2 } #check { c2 with x.1 := 3 }
cd665de05ea07b006155d2194471b130f201ec4c
4727251e0cd73359b15b664c3170e5d754078599
/src/algebra/module/submodule/pointwise.lean
a435d5e19af335ee98dd6e2c9566c4ed16944861
[ "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
7,027
lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import group_theory.subgroup.pointwise import linear_algebra.span /-! # Pointwise instances on `submodule`s This file provides: * `submodule.has_pointwise_neg` and the actions * `submodule.pointwise_distrib_mul_action` * `submodule.pointwise_mul_action_with_zero` which matches the action of `mul_action_set`. These actions are available in the `pointwise` locale. ## Implementation notes Most of the lemmas in this file are direct copies of lemmas from `group_theory/submonoid/pointwise.lean`. -/ variables {α : Type*} {R : Type*} {M : Type*} open_locale pointwise namespace submodule section neg section semiring variables [semiring R] [add_comm_group M] [module R M] /-- The submodule with every element negated. Note if `R` is a ring and not just a semiring, this is a no-op, as shown by `submodule.neg_eq_self`. Recall that When `R` is the semiring corresponding to the nonnegative elements of `R'`, `submodule R' M` is the type of cones of `M`. This instance reflects such cones about `0`. This is available as an instance in the `pointwise` locale. -/ protected def has_pointwise_neg : has_neg (submodule R M) := { neg := λ p, { carrier := -(p : set M), smul_mem' := λ r m hm, set.mem_neg.2 $ smul_neg r m ▸ p.smul_mem r $ set.mem_neg.1 hm, ..(- p.to_add_submonoid) } } localized "attribute [instance] submodule.has_pointwise_neg" in pointwise open_locale pointwise @[simp] lemma coe_set_neg (S : submodule R M) : ↑(-S) = -(S : set M) := rfl @[simp] lemma neg_to_add_submonoid (S : submodule R M) : (-S).to_add_submonoid = -S.to_add_submonoid := rfl @[simp] lemma mem_neg {g : M} {S : submodule R M} : g ∈ -S ↔ -g ∈ S := iff.rfl /-- `submodule.has_pointwise_neg` is involutive. This is available as an instance in the `pointwise` locale. -/ protected def has_involutive_pointwise_neg : has_involutive_neg (submodule R M) := { neg := has_neg.neg, neg_neg := λ S, set_like.coe_injective $ neg_neg _ } localized "attribute [instance] submodule.has_involutive_pointwise_neg" in pointwise @[simp] lemma neg_le_neg (S T : submodule R M) : -S ≤ -T ↔ S ≤ T := set_like.coe_subset_coe.symm.trans set.neg_subset_neg lemma neg_le (S T : submodule R M) : -S ≤ T ↔ S ≤ -T := set_like.coe_subset_coe.symm.trans set.neg_subset /-- `submodule.has_pointwise_neg` as an order isomorphism. -/ def neg_order_iso : submodule R M ≃o submodule R M := { to_equiv := equiv.neg _, map_rel_iff' := neg_le_neg } lemma closure_neg (s : set M) : span R (-s) = -(span R s) := begin apply le_antisymm, { rw [span_le, coe_set_neg, ←set.neg_subset, neg_neg], exact subset_span }, { rw [neg_le, span_le, coe_set_neg, ←set.neg_subset], exact subset_span } end @[simp] lemma neg_inf (S T : submodule R M) : -(S ⊓ T) = (-S) ⊓ (-T) := set_like.coe_injective set.inter_neg @[simp] lemma neg_sup (S T : submodule R M) : -(S ⊔ T) = (-S) ⊔ (-T) := (neg_order_iso : submodule R M ≃o submodule R M).map_sup S T @[simp] lemma neg_bot : -(⊥ : submodule R M) = ⊥ := set_like.coe_injective $ (set.neg_singleton 0).trans $ congr_arg _ neg_zero @[simp] lemma neg_top : -(⊤ : submodule R M) = ⊤ := set_like.coe_injective $ set.neg_univ @[simp] lemma neg_infi {ι : Sort*} (S : ι → submodule R M) : -(⨅ i, S i) = ⨅ i, -S i := (neg_order_iso : submodule R M ≃o submodule R M).map_infi _ @[simp] lemma neg_supr {ι : Sort*} (S : ι → submodule R M) : -(⨆ i, S i) = ⨆ i, -(S i) := (neg_order_iso : submodule R M ≃o submodule R M).map_supr _ end semiring open_locale pointwise @[simp] lemma neg_eq_self [ring R] [add_comm_group M] [module R M] (p : submodule R M) : -p = p := ext $ λ _, p.neg_mem_iff end neg variables [semiring R] [add_comm_monoid M] [module R M] instance pointwise_add_comm_monoid : add_comm_monoid (submodule R M) := { add := (⊔), add_assoc := λ _ _ _, sup_assoc, zero := ⊥, zero_add := λ _, bot_sup_eq, add_zero := λ _, sup_bot_eq, add_comm := λ _ _, sup_comm } @[simp] lemma add_eq_sup (p q : submodule R M) : p + q = p ⊔ q := rfl @[simp] lemma zero_eq_bot : (0 : submodule R M) = ⊥ := rfl section variables [monoid α] [distrib_mul_action α M] [smul_comm_class α R M] /-- The action on a submodule corresponding to applying the action to every element. This is available as an instance in the `pointwise` locale. -/ protected def pointwise_distrib_mul_action : distrib_mul_action α (submodule R M) := { smul := λ a S, S.map (distrib_mul_action.to_linear_map _ _ a), one_smul := λ S, (congr_arg (λ f, S.map f) (linear_map.ext $ by exact one_smul α)).trans S.map_id, mul_smul := λ a₁ a₂ S, (congr_arg (λ f : M →ₗ[R] M, S.map f) (linear_map.ext $ by exact mul_smul _ _)).trans (S.map_comp _ _), smul_zero := λ a, map_bot _, smul_add := λ a S₁ S₂, map_sup _ _ _ } localized "attribute [instance] submodule.pointwise_distrib_mul_action" in pointwise open_locale pointwise @[simp] lemma coe_pointwise_smul (a : α) (S : submodule R M) : ↑(a • S) = a • (S : set M) := rfl @[simp] lemma pointwise_smul_to_add_submonoid (a : α) (S : submodule R M) : (a • S).to_add_submonoid = a • S.to_add_submonoid := rfl @[simp] lemma pointwise_smul_to_add_subgroup {R M : Type*} [ring R] [add_comm_group M] [distrib_mul_action α M] [module R M] [smul_comm_class α R M] (a : α) (S : submodule R M) : (a • S).to_add_subgroup = a • S.to_add_subgroup := rfl lemma smul_mem_pointwise_smul (m : M) (a : α) (S : submodule R M) : m ∈ S → a • m ∈ a • S := (set.smul_mem_smul_set : _ → _ ∈ a • (S : set M)) instance pointwise_central_scalar [distrib_mul_action αᵐᵒᵖ M] [smul_comm_class αᵐᵒᵖ R M] [is_central_scalar α M] : is_central_scalar α (submodule R M) := ⟨λ a S, congr_arg (λ f, S.map f) $ linear_map.ext $ by exact op_smul_eq_smul _⟩ @[simp] lemma smul_le_self_of_tower {α : Type*} [semiring α] [module α R] [module α M] [smul_comm_class α R M] [is_scalar_tower α R M] (a : α) (S : submodule R M) : a • S ≤ S := begin rintro y ⟨x, hx, rfl⟩, exact smul_of_tower_mem _ a hx, end end section variables [semiring α] [module α M] [smul_comm_class α R M] /-- The action on a submodule corresponding to applying the action to every element. This is available as an instance in the `pointwise` locale. This is a stronger version of `submodule.pointwise_distrib_mul_action`. Note that `add_smul` does not hold so this cannot be stated as a `module`. -/ protected def pointwise_mul_action_with_zero : mul_action_with_zero α (submodule R M) := { zero_smul := λ S, (congr_arg (λ f : M →ₗ[R] M, S.map f) (linear_map.ext $ by exact zero_smul α)).trans S.map_zero, .. submodule.pointwise_distrib_mul_action } localized "attribute [instance] submodule.pointwise_mul_action_with_zero" in pointwise end end submodule
c44d5bdafcee7170801ab8fb6cba948b61d85483
9dc8cecdf3c4634764a18254e94d43da07142918
/archive/imo/imo2008_q3.lean
e4c807c149fa40fba60f38f5b377f26a5b8ba395
[ "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
3,827
lean
/- Copyright (c) 2021 Manuel Candales. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Manuel Candales -/ import data.real.basic import data.real.sqrt import data.nat.prime import number_theory.primes_congruent_one import number_theory.legendre_symbol.quadratic_reciprocity import tactic.linear_combination /-! # IMO 2008 Q3 Prove that there exist infinitely many positive integers `n` such that `n^2 + 1` has a prime divisor which is greater than `2n + √(2n)`. # Solution We first prove the following lemma: for every prime `p > 20`, satisfying `p ≡ 1 [MOD 4]`, there exists `n ∈ ℕ` such that `p ∣ n^2 + 1` and `p > 2n + √(2n)`. Then the statement of the problem follows from the fact that there exist infinitely many primes `p ≡ 1 [MOD 4]`. To prove the lemma, notice that `p ≡ 1 [MOD 4]` implies `∃ n ∈ ℕ` such that `n^2 ≡ -1 [MOD p]` and we can take this `n` such that `n ≤ p/2`. Let `k = p - 2n ≥ 0`. Then we have: `k^2 + 4 = (p - 2n)^2 + 4 ≣ 4n^2 + 4 ≡ 0 [MOD p]`. Then `k^2 + 4 ≥ p` and so `k ≥ √(p - 4) > 4`. Then `p = 2n + k ≥ 2n + √(p - 4) = 2n + √(2n + k - 4) > √(2n)` and we are done. -/ open real lemma p_lemma (p : ℕ) (hpp : nat.prime p) (hp_mod_4_eq_1 : p ≡ 1 [MOD 4]) (hp_gt_20 : p > 20) : ∃ n : ℕ, p ∣ n ^ 2 + 1 ∧ (p : ℝ) > 2 * n + sqrt(2 * n) := begin haveI := fact.mk hpp, have hp_mod_4_ne_3 : p % 4 ≠ 3, { linarith [(show p % 4 = 1, by exact hp_mod_4_eq_1)] }, obtain ⟨y, hy⟩ := zmod.exists_sq_eq_neg_one_iff.mpr hp_mod_4_ne_3, let m := zmod.val_min_abs y, let n := int.nat_abs m, have hnat₁ : p ∣ n ^ 2 + 1, { refine int.coe_nat_dvd.mp _, simp only [int.nat_abs_sq, int.coe_nat_pow, int.coe_nat_succ, int.coe_nat_dvd.mp], refine (zmod.int_coe_zmod_eq_zero_iff_dvd (m ^ 2 + 1) p).mp _, simp only [int.cast_pow, int.cast_add, int.cast_one, zmod.coe_val_min_abs], rw [pow_two, ← hy], exact add_left_neg 1 }, have hnat₂ : n ≤ p / 2 := zmod.nat_abs_val_min_abs_le y, have hnat₃ : p ≥ 2 * n, { linarith [nat.div_mul_le_self p 2] }, set k : ℕ := p - 2 * n with hnat₄, have hnat₅ : p ∣ k ^ 2 + 4, { cases hnat₁ with x hx, have : (p:ℤ) ∣ k ^ 2 + 4, { use (p:ℤ) - 4 * n + 4 * x, have hcast₁ : (k:ℤ) = p - 2 * n, { assumption_mod_cast }, have hcast₂ : (n:ℤ) ^ 2 + 1 = p * x, { assumption_mod_cast }, linear_combination ((k:ℤ) + p - 2 * n)*hcast₁ + 4*hcast₂ }, assumption_mod_cast }, have hnat₆ : k ^ 2 + 4 ≥ p := nat.le_of_dvd (k ^ 2 + 3).succ_pos hnat₅, have hreal₁ : (k:ℝ) = p - 2 * n, { assumption_mod_cast }, have hreal₂ : (p:ℝ) > 20, { assumption_mod_cast }, have hreal₃ : (k:ℝ) ^ 2 + 4 ≥ p, { assumption_mod_cast }, have hreal₅ : (k:ℝ) > 4, { apply lt_of_pow_lt_pow 2 k.cast_nonneg, linarith only [hreal₂, hreal₃] }, have hreal₆ : (k:ℝ) > sqrt (2 * n), { apply lt_of_pow_lt_pow 2 k.cast_nonneg, rw sq_sqrt (mul_nonneg zero_le_two n.cast_nonneg), linarith only [hreal₁, hreal₃, hreal₅] }, exact ⟨n, hnat₁, by linarith only [hreal₆, hreal₁]⟩, end theorem imo2008_q3 : ∀ N : ℕ, ∃ n : ℕ, n ≥ N ∧ ∃ p : ℕ, nat.prime p ∧ p ∣ n ^ 2 + 1 ∧ (p : ℝ) > 2 * n + sqrt(2 * n) := begin intro N, obtain ⟨p, hpp, hineq₁, hpmod4⟩ := nat.exists_prime_ge_modeq_one (N ^ 2 + 21) zero_lt_four, obtain ⟨n, hnat, hreal⟩ := p_lemma p hpp hpmod4 (by linarith [hineq₁, nat.zero_le (N ^ 2)]), have hineq₂ : n ^ 2 + 1 ≥ p := nat.le_of_dvd (n ^ 2).succ_pos hnat, have hineq₃ : n * n ≥ N * N, { linarith [hineq₁, hineq₂] }, have hn_ge_N : n ≥ N := nat.mul_self_le_mul_self_iff.mpr hineq₃, exact ⟨n, hn_ge_N, p, hpp, hnat, hreal⟩, end
e2a9500b6af7c5961dda4d9849f78040f872056c
b7f22e51856f4989b970961f794f1c435f9b8f78
/tests/lean/hott/tele_eq.hlean
f38bf4b3d1ca8764cf026ff852e5722b78bfcd32
[ "Apache-2.0" ]
permissive
soonhokong/lean
cb8aa01055ffe2af0fb99a16b4cda8463b882cd1
38607e3eb57f57f77c0ac114ad169e9e4262e24f
refs/heads/master
1,611,187,284,081
1,450,766,737,000
1,476,122,547,000
11,513,992
2
0
null
1,401,763,102,000
1,374,182,235,000
C++
UTF-8
Lean
false
false
599
hlean
constant A₁ : Type constant A₂ : A₁ → Type constant A₃ : Π (a₁ : A₁), A₂ a₁ → Type structure foo := mk :: (a₁ : A₁) (a₂ : A₂ a₁) (a₃ : A₃ a₁ a₂) theorem foo.eq {a₁ b₁ : A₁} {a₂ : A₂ a₁} {b₂ : A₂ b₁} {a₃ : A₃ a₁ a₂} {b₃ : A₃ b₁ b₂} (H₁ : a₁ = b₁) (H₂ : eq.rec_on H₁ a₂ = b₂) (H₃ : eq.rec_on H₂ (eq.rec_on H₁ a₃) = b₃) : foo.mk a₁ a₂ a₃ = foo.mk b₁ b₂ b₃ := begin cases H₁, cases H₂, cases H₃, apply rfl end reveal foo.eq print definition foo.eq
028998fb4b41a05e9e9e3670eb304d6cf63bba68
626e312b5c1cb2d88fca108f5933076012633192
/src/analysis/normed_space/operator_norm.lean
35709e9197aee0aef48e79da0517ce0ed89e98f5
[ "Apache-2.0" ]
permissive
Bioye97/mathlib
9db2f9ee54418d29dd06996279ba9dc874fd6beb
782a20a27ee83b523f801ff34efb1a9557085019
refs/heads/master
1,690,305,956,488
1,631,067,774,000
1,631,067,774,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
58,293
lean
/- Copyright (c) 2019 Jan-David Salchow. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jan-David Salchow, Sébastien Gouëzel, Jean Lo -/ import algebra.algebra.tower import analysis.normed_space.linear_isometry import analysis.normed_space.riesz_lemma import data.equiv.transfer_instance /-! # Operator norm on the space of continuous linear maps Define the operator norm on the space of continuous linear maps between normed spaces, and prove its basic properties. In particular, show that this space is itself a normed space. Since a lot of elementary properties don't require `∥x∥ = 0 → x = 0` we start setting up the theory for `semi_normed_space` and we specialize to `normed_space` at the end. -/ noncomputable theory open_locale classical nnreal topological_space variables {𝕜 : Type*} {E : Type*} {F : Type*} {G : Type*} section semi_normed variables [semi_normed_group E] [semi_normed_group F] [semi_normed_group G] open metric continuous_linear_map section normed_field /-! Most statements in this file require the field to be non-discrete, as this is necessary to deduce an inequality `∥f x∥ ≤ C ∥x∥` from the continuity of f. However, the other direction always holds. In this section, we just assume that `𝕜` is a normed field. In the remainder of the file, it will be non-discrete. -/ variables [normed_field 𝕜] [semi_normed_space 𝕜 E] [semi_normed_space 𝕜 F] (f : E →ₗ[𝕜] F) lemma linear_map.lipschitz_of_bound (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : lipschitz_with (real.to_nnreal C) f := f.to_add_monoid_hom.lipschitz_of_bound C h lemma linear_map.lipschitz_of_bound_nnnorm (C : ℝ≥0) (h : ∀ x, ∥f x∥₊ ≤ C * ∥x∥₊) : lipschitz_with C f := f.to_add_monoid_hom.lipschitz_of_bound_nnnorm C h theorem linear_map.antilipschitz_of_bound {K : ℝ≥0} (h : ∀ x, ∥x∥ ≤ K * ∥f x∥) : antilipschitz_with K f := antilipschitz_with.of_le_mul_dist $ λ x y, by simpa only [dist_eq_norm, f.map_sub] using h (x - y) lemma linear_map.bound_of_antilipschitz {K : ℝ≥0} (h : antilipschitz_with K f) (x) : ∥x∥ ≤ K * ∥f x∥ := by simpa only [dist_zero_right, f.map_zero] using h.le_mul_dist x 0 lemma linear_map.uniform_continuous_of_bound (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : uniform_continuous f := (f.lipschitz_of_bound C h).uniform_continuous lemma linear_map.continuous_of_bound (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : continuous f := (f.lipschitz_of_bound C h).continuous /-- Construct a continuous linear map from a linear map and a bound on this linear map. The fact that the norm of the continuous linear map is then controlled is given in `linear_map.mk_continuous_norm_le`. -/ def linear_map.mk_continuous (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : E →L[𝕜] F := ⟨f, linear_map.continuous_of_bound f C h⟩ /-- Reinterpret a linear map `𝕜 →ₗ[𝕜] E` as a continuous linear map. This construction is generalized to the case of any finite dimensional domain in `linear_map.to_continuous_linear_map`. -/ def linear_map.to_continuous_linear_map₁ (f : 𝕜 →ₗ[𝕜] E) : 𝕜 →L[𝕜] E := f.mk_continuous (∥f 1∥) $ λ x, le_of_eq $ by { conv_lhs { rw ← mul_one x }, rw [← smul_eq_mul, f.map_smul, norm_smul, mul_comm] } /-- Construct a continuous linear map from a linear map and the existence of a bound on this linear map. If you have an explicit bound, use `linear_map.mk_continuous` instead, as a norm estimate will follow automatically in `linear_map.mk_continuous_norm_le`. -/ def linear_map.mk_continuous_of_exists_bound (h : ∃C, ∀x, ∥f x∥ ≤ C * ∥x∥) : E →L[𝕜] F := ⟨f, let ⟨C, hC⟩ := h in linear_map.continuous_of_bound f C hC⟩ lemma continuous_of_linear_of_bound {f : E → F} (h_add : ∀ x y, f (x + y) = f x + f y) (h_smul : ∀ (c : 𝕜) x, f (c • x) = c • f x) {C : ℝ} (h_bound : ∀ x, ∥f x∥ ≤ C*∥x∥) : continuous f := let φ : E →ₗ[𝕜] F := { to_fun := f, map_add' := h_add, map_smul' := h_smul } in φ.continuous_of_bound C h_bound @[simp, norm_cast] lemma linear_map.mk_continuous_coe (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : ((f.mk_continuous C h) : E →ₗ[𝕜] F) = f := rfl @[simp] lemma linear_map.mk_continuous_apply (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) (x : E) : f.mk_continuous C h x = f x := rfl @[simp, norm_cast] lemma linear_map.mk_continuous_of_exists_bound_coe (h : ∃C, ∀x, ∥f x∥ ≤ C * ∥x∥) : ((f.mk_continuous_of_exists_bound h) : E →ₗ[𝕜] F) = f := rfl @[simp] lemma linear_map.mk_continuous_of_exists_bound_apply (h : ∃C, ∀x, ∥f x∥ ≤ C * ∥x∥) (x : E) : f.mk_continuous_of_exists_bound h x = f x := rfl @[simp] lemma linear_map.to_continuous_linear_map₁_coe (f : 𝕜 →ₗ[𝕜] E) : (f.to_continuous_linear_map₁ : 𝕜 →ₗ[𝕜] E) = f := rfl @[simp] lemma linear_map.to_continuous_linear_map₁_apply (f : 𝕜 →ₗ[𝕜] E) (x) : f.to_continuous_linear_map₁ x = f x := rfl end normed_field variables [nondiscrete_normed_field 𝕜] [semi_normed_space 𝕜 E] [semi_normed_space 𝕜 F] [semi_normed_space 𝕜 G] (c : 𝕜) (f g : E →L[𝕜] F) (h : F →L[𝕜] G) (x y z : E) include 𝕜 lemma linear_map.bound_of_shell_semi_normed (f : E →ₗ[𝕜] F) {ε C : ℝ} (ε_pos : 0 < ε) {c : 𝕜} (hc : 1 < ∥c∥) (hf : ∀ x, ε / ∥c∥ ≤ ∥x∥ → ∥x∥ < ε → ∥f x∥ ≤ C * ∥x∥) {x : E} (hx : ∥x∥ ≠ 0) : ∥f x∥ ≤ C * ∥x∥ := begin rcases rescale_to_shell_semi_normed hc ε_pos hx with ⟨δ, hδ, δxle, leδx, δinv⟩, simpa only [f.map_smul, norm_smul, mul_left_comm C, mul_le_mul_left (norm_pos_iff.2 hδ)] using hf (δ • x) leδx δxle end /-- If `∥x∥ = 0` and `f` is continuous then `∥f x∥ = 0`. -/ lemma norm_image_of_norm_zero {f : E →ₗ[𝕜] F} (hf : continuous f) {x : E} (hx : ∥x∥ = 0) : ∥f x∥ = 0 := begin refine le_antisymm (le_of_forall_pos_le_add (λ ε hε, _)) (norm_nonneg (f x)), rcases normed_group.tendsto_nhds_nhds.1 (hf.tendsto 0) ε hε with ⟨δ, δ_pos, hδ⟩, replace hδ := hδ x, rw [sub_zero, hx] at hδ, replace hδ := le_of_lt (hδ δ_pos), rw [linear_map.map_zero, sub_zero] at hδ, rwa [zero_add] end /-- A continuous linear map between seminormed spaces is bounded when the field is nondiscrete. The continuity ensures boundedness on a ball of some radius `ε`. The nondiscreteness is then used to rescale any element into an element of norm in `[ε/C, ε]`, whose image has a controlled norm. The norm control for the original element follows by rescaling. -/ lemma linear_map.bound_of_continuous (f : E →ₗ[𝕜] F) (hf : continuous f) : ∃ C, 0 < C ∧ (∀ x : E, ∥f x∥ ≤ C * ∥x∥) := begin rcases normed_group.tendsto_nhds_nhds.1 (hf.tendsto 0) 1 zero_lt_one with ⟨ε, ε_pos, hε⟩, simp only [sub_zero, f.map_zero] at hε, rcases normed_field.exists_one_lt_norm 𝕜 with ⟨c, hc⟩, have : 0 < ∥c∥ / ε, from div_pos (zero_lt_one.trans hc) ε_pos, refine ⟨∥c∥ / ε, this, λ x, _⟩, by_cases hx : ∥x∥ = 0, { rw [hx, mul_zero], exact le_of_eq (norm_image_of_norm_zero hf hx) }, refine f.bound_of_shell_semi_normed ε_pos hc (λ x hle hlt, _) hx, refine (hε _ hlt).le.trans _, rwa [← div_le_iff' this, one_div_div] end namespace continuous_linear_map theorem bound : ∃ C, 0 < C ∧ (∀ x : E, ∥f x∥ ≤ C * ∥x∥) := f.to_linear_map.bound_of_continuous f.2 section open filter /-- A linear map which is a homothety is a continuous linear map. Since the field `𝕜` need not have `ℝ` as a subfield, this theorem is not directly deducible from the corresponding theorem about isometries plus a theorem about scalar multiplication. Likewise for the other theorems about homotheties in this file. -/ def of_homothety (f : E →ₗ[𝕜] F) (a : ℝ) (hf : ∀x, ∥f x∥ = a * ∥x∥) : E →L[𝕜] F := f.mk_continuous a (λ x, le_of_eq (hf x)) variable (𝕜) lemma to_span_singleton_homothety (x : E) (c : 𝕜) : ∥linear_map.to_span_singleton 𝕜 E x c∥ = ∥x∥ * ∥c∥ := by {rw mul_comm, exact norm_smul _ _} /-- Given an element `x` of a normed space `E` over a field `𝕜`, the natural continuous linear map from `E` to the span of `x`.-/ def to_span_singleton (x : E) : 𝕜 →L[𝕜] E := of_homothety (linear_map.to_span_singleton 𝕜 E x) ∥x∥ (to_span_singleton_homothety 𝕜 x) end section op_norm open set real /-- The operator norm of a continuous linear map is the inf of all its bounds. -/ def op_norm := Inf {c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥} instance has_op_norm : has_norm (E →L[𝕜] F) := ⟨op_norm⟩ lemma norm_def : ∥f∥ = Inf {c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥} := rfl -- So that invocations of `le_cInf` make sense: we show that the set of -- bounds is nonempty and bounded below. lemma bounds_nonempty {f : E →L[𝕜] F} : ∃ c, c ∈ { c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥ } := let ⟨M, hMp, hMb⟩ := f.bound in ⟨M, le_of_lt hMp, hMb⟩ lemma bounds_bdd_below {f : E →L[𝕜] F} : bdd_below { c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥ } := ⟨0, λ _ ⟨hn, _⟩, hn⟩ lemma op_norm_nonneg : 0 ≤ ∥f∥ := le_cInf bounds_nonempty (λ _ ⟨hx, _⟩, hx) /-- The fundamental property of the operator norm: `∥f x∥ ≤ ∥f∥ * ∥x∥`. -/ theorem le_op_norm : ∥f x∥ ≤ ∥f∥ * ∥x∥ := begin obtain ⟨C, Cpos, hC⟩ := f.bound, replace hC := hC x, by_cases h : ∥x∥ = 0, { rwa [h, mul_zero] at ⊢ hC }, have hlt : 0 < ∥x∥ := lt_of_le_of_ne (norm_nonneg x) (ne.symm h), exact (div_le_iff hlt).mp (le_cInf bounds_nonempty (λ c ⟨_, hc⟩, (div_le_iff hlt).mpr $ by { apply hc })), end theorem le_op_norm_of_le {c : ℝ} {x} (h : ∥x∥ ≤ c) : ∥f x∥ ≤ ∥f∥ * c := le_trans (f.le_op_norm x) (mul_le_mul_of_nonneg_left h f.op_norm_nonneg) theorem le_of_op_norm_le {c : ℝ} (h : ∥f∥ ≤ c) (x : E) : ∥f x∥ ≤ c * ∥x∥ := (f.le_op_norm x).trans (mul_le_mul_of_nonneg_right h (norm_nonneg x)) lemma ratio_le_op_norm : ∥f x∥ / ∥x∥ ≤ ∥f∥ := div_le_of_nonneg_of_le_mul (norm_nonneg _) f.op_norm_nonneg (le_op_norm _ _) /-- The image of the unit ball under a continuous linear map is bounded. -/ lemma unit_le_op_norm : ∥x∥ ≤ 1 → ∥f x∥ ≤ ∥f∥ := mul_one ∥f∥ ▸ f.le_op_norm_of_le /-- If one controls the norm of every `A x`, then one controls the norm of `A`. -/ lemma op_norm_le_bound {M : ℝ} (hMp: 0 ≤ M) (hM : ∀ x, ∥f x∥ ≤ M * ∥x∥) : ∥f∥ ≤ M := cInf_le bounds_bdd_below ⟨hMp, hM⟩ theorem op_norm_le_of_lipschitz {f : E →L[𝕜] F} {K : ℝ≥0} (hf : lipschitz_with K f) : ∥f∥ ≤ K := f.op_norm_le_bound K.2 $ λ x, by simpa only [dist_zero_right, f.map_zero] using hf.dist_le_mul x 0 lemma op_norm_le_of_shell {f : E →L[𝕜] F} {ε C : ℝ} (ε_pos : 0 < ε) (hC : 0 ≤ C) {c : 𝕜} (hc : 1 < ∥c∥) (hf : ∀ x, ε / ∥c∥ ≤ ∥x∥ → ∥x∥ < ε → ∥f x∥ ≤ C * ∥x∥) : ∥f∥ ≤ C := begin refine f.op_norm_le_bound hC (λ x, _), by_cases hx : ∥x∥ = 0, { rw [hx, mul_zero], exact le_of_eq (norm_image_of_norm_zero f.2 hx) }, exact linear_map.bound_of_shell_semi_normed f ε_pos hc hf hx end lemma op_norm_le_of_ball {f : E →L[𝕜] F} {ε : ℝ} {C : ℝ} (ε_pos : 0 < ε) (hC : 0 ≤ C) (hf : ∀ x ∈ ball (0 : E) ε, ∥f x∥ ≤ C * ∥x∥) : ∥f∥ ≤ C := begin rcases normed_field.exists_one_lt_norm 𝕜 with ⟨c, hc⟩, refine op_norm_le_of_shell ε_pos hC hc (λ x _ hx, hf x _), rwa ball_0_eq end lemma op_norm_le_of_nhds_zero {f : E →L[𝕜] F} {C : ℝ} (hC : 0 ≤ C) (hf : ∀ᶠ x in 𝓝 (0 : E), ∥f x∥ ≤ C * ∥x∥) : ∥f∥ ≤ C := let ⟨ε, ε0, hε⟩ := metric.eventually_nhds_iff_ball.1 hf in op_norm_le_of_ball ε0 hC hε lemma op_norm_le_of_shell' {f : E →L[𝕜] F} {ε C : ℝ} (ε_pos : 0 < ε) (hC : 0 ≤ C) {c : 𝕜} (hc : ∥c∥ < 1) (hf : ∀ x, ε * ∥c∥ ≤ ∥x∥ → ∥x∥ < ε → ∥f x∥ ≤ C * ∥x∥) : ∥f∥ ≤ C := begin by_cases h0 : c = 0, { refine op_norm_le_of_ball ε_pos hC (λ x hx, hf x _ _), { simp [h0] }, { rwa ball_0_eq at hx } }, { rw [← inv_inv' c, normed_field.norm_inv, inv_lt_one_iff_of_pos (norm_pos_iff.2 $ inv_ne_zero h0)] at hc, refine op_norm_le_of_shell ε_pos hC hc _, rwa [normed_field.norm_inv, div_eq_mul_inv, inv_inv'] } end lemma op_norm_eq_of_bounds {φ : E →L[𝕜] F} {M : ℝ} (M_nonneg : 0 ≤ M) (h_above : ∀ x, ∥φ x∥ ≤ M*∥x∥) (h_below : ∀ N ≥ 0, (∀ x, ∥φ x∥ ≤ N*∥x∥) → M ≤ N) : ∥φ∥ = M := le_antisymm (φ.op_norm_le_bound M_nonneg h_above) ((le_cInf_iff continuous_linear_map.bounds_bdd_below ⟨M, M_nonneg, h_above⟩).mpr $ λ N ⟨N_nonneg, hN⟩, h_below N N_nonneg hN) /-- The operator norm satisfies the triangle inequality. -/ theorem op_norm_add_le : ∥f + g∥ ≤ ∥f∥ + ∥g∥ := (f + g).op_norm_le_bound (add_nonneg f.op_norm_nonneg g.op_norm_nonneg) $ λ x, (norm_add_le_of_le (f.le_op_norm x) (g.le_op_norm x)).trans_eq (add_mul _ _ _).symm /-- The norm of the `0` operator is `0`. -/ theorem op_norm_zero : ∥(0 : E →L[𝕜] F)∥ = 0 := le_antisymm (cInf_le bounds_bdd_below ⟨ge_of_eq rfl, λ _, le_of_eq (by { rw [zero_mul], exact norm_zero })⟩) (op_norm_nonneg _) /-- The norm of the identity is at most `1`. It is in fact `1`, except when the space is trivial where it is `0`. It means that one can not do better than an inequality in general. -/ lemma norm_id_le : ∥id 𝕜 E∥ ≤ 1 := op_norm_le_bound _ zero_le_one (λx, by simp) /-- If there is an element with norm different from `0`, then the norm of the identity equals `1`. (Since we are working with seminorms supposing that the space is non-trivial is not enough.) -/ lemma norm_id_of_nontrivial_seminorm (h : ∃ (x : E), ∥x∥ ≠ 0) : ∥id 𝕜 E∥ = 1 := le_antisymm norm_id_le $ let ⟨x, hx⟩ := h in have _ := (id 𝕜 E).ratio_le_op_norm x, by rwa [id_apply, div_self hx] at this lemma op_norm_smul_le {𝕜' : Type*} [normed_field 𝕜'] [semi_normed_space 𝕜' F] [smul_comm_class 𝕜 𝕜' F] (c : 𝕜') (f : E →L[𝕜] F) : ∥c • f∥ ≤ ∥c∥ * ∥f∥ := ((c • f).op_norm_le_bound (mul_nonneg (norm_nonneg _) (op_norm_nonneg _)) (λ _, begin erw [norm_smul, mul_assoc], exact mul_le_mul_of_nonneg_left (le_op_norm _ _) (norm_nonneg _) end)) lemma op_norm_neg : ∥-f∥ = ∥f∥ := by simp only [norm_def, neg_apply, norm_neg] /-- Continuous linear maps themselves form a seminormed space with respect to the operator norm. -/ instance to_semi_normed_group : semi_normed_group (E →L[𝕜] F) := semi_normed_group.of_core _ ⟨op_norm_zero, op_norm_add_le, op_norm_neg⟩ instance to_semi_normed_space {𝕜' : Type*} [normed_field 𝕜'] [semi_normed_space 𝕜' F] [smul_comm_class 𝕜 𝕜' F] : semi_normed_space 𝕜' (E →L[𝕜] F) := ⟨op_norm_smul_le⟩ /-- The operator norm is submultiplicative. -/ lemma op_norm_comp_le (f : E →L[𝕜] F) : ∥h.comp f∥ ≤ ∥h∥ * ∥f∥ := (cInf_le bounds_bdd_below ⟨mul_nonneg (op_norm_nonneg _) (op_norm_nonneg _), λ x, by { rw mul_assoc, exact h.le_op_norm_of_le (f.le_op_norm x) } ⟩) /-- Continuous linear maps form a seminormed ring with respect to the operator norm. -/ instance to_semi_normed_ring : semi_normed_ring (E →L[𝕜] E) := { norm_mul := op_norm_comp_le, .. continuous_linear_map.to_semi_normed_group } theorem le_op_nnnorm : ∥f x∥₊ ≤ ∥f∥₊ * ∥x∥₊ := f.le_op_norm x /-- continuous linear maps are Lipschitz continuous. -/ theorem lipschitz : lipschitz_with ∥f∥₊ f := (f : E →ₗ[𝕜] F).lipschitz_of_bound_nnnorm _ f.le_op_nnnorm theorem le_op_norm₂ (f : E →L[𝕜] F →L[𝕜] G) (x : E) (y : F) : ∥f x y∥ ≤ ∥f∥ * ∥x∥ * ∥y∥ := (f x).le_of_op_norm_le (f.le_op_norm x) y theorem op_norm_le_bound₂ (f : E →L[𝕜] F →L[𝕜] G) {C : ℝ} (h0 : 0 ≤ C) (hC : ∀ x y, ∥f x y∥ ≤ C * ∥x∥ * ∥y∥) : ∥f∥ ≤ C := f.op_norm_le_bound h0 $ λ x, (f x).op_norm_le_bound (mul_nonneg h0 (norm_nonneg _)) $ hC x @[simp] lemma op_norm_prod (f : E →L[𝕜] F) (g : E →L[𝕜] G) : ∥f.prod g∥ = ∥(f, g)∥ := le_antisymm (op_norm_le_bound _ (norm_nonneg _) $ λ x, by simpa only [prod_apply, prod.semi_norm_def, max_mul_of_nonneg, norm_nonneg] using max_le_max (le_op_norm f x) (le_op_norm g x)) $ max_le (op_norm_le_bound _ (norm_nonneg _) $ λ x, (le_max_left _ _).trans ((f.prod g).le_op_norm x)) (op_norm_le_bound _ (norm_nonneg _) $ λ x, (le_max_right _ _).trans ((f.prod g).le_op_norm x)) /-- `continuous_linear_map.prod` as a `linear_isometry_equiv`. -/ def prodₗᵢ (R : Type*) [ring R] [topological_space R] [module R F] [module R G] [has_continuous_smul R F] [has_continuous_smul R G] [smul_comm_class 𝕜 R F] [smul_comm_class 𝕜 R G] : (E →L[𝕜] F) × (E →L[𝕜] G) ≃ₗᵢ[R] (E →L[𝕜] F × G) := ⟨prodₗ R, λ ⟨f, g⟩, op_norm_prod f g⟩ /-- A continuous linear map is automatically uniformly continuous. -/ protected theorem uniform_continuous : uniform_continuous f := f.lipschitz.uniform_continuous @[simp, nontriviality] lemma op_norm_subsingleton [subsingleton E] : ∥f∥ = 0 := begin refine le_antisymm _ (norm_nonneg _), apply op_norm_le_bound _ rfl.ge, intros x, simp [subsingleton.elim x 0] end /-- A continuous linear map is an isometry if and only if it preserves the norm. -/ lemma isometry_iff_norm : isometry f ↔ ∀x, ∥f x∥ = ∥x∥ := f.to_linear_map.to_add_monoid_hom.isometry_iff_norm end op_norm section is_O open asymptotics theorem is_O_with_id (l : filter E) : is_O_with ∥f∥ f (λ x, x) l := is_O_with_of_le' _ f.le_op_norm theorem is_O_id (l : filter E) : is_O f (λ x, x) l := (f.is_O_with_id l).is_O theorem is_O_with_comp {α : Type*} (g : F →L[𝕜] G) (f : α → F) (l : filter α) : is_O_with ∥g∥ (λ x', g (f x')) f l := (g.is_O_with_id ⊤).comp_tendsto le_top theorem is_O_comp {α : Type*} (g : F →L[𝕜] G) (f : α → F) (l : filter α) : is_O (λ x', g (f x')) f l := (g.is_O_with_comp f l).is_O theorem is_O_with_sub (f : E →L[𝕜] F) (l : filter E) (x : E) : is_O_with ∥f∥ (λ x', f (x' - x)) (λ x', x' - x) l := f.is_O_with_comp _ l theorem is_O_sub (f : E →L[𝕜] F) (l : filter E) (x : E) : is_O (λ x', f (x' - x)) (λ x', x' - x) l := f.is_O_comp _ l end is_O end continuous_linear_map namespace linear_isometry lemma norm_to_continuous_linear_map_le (f : E →ₗᵢ[𝕜] F) : ∥f.to_continuous_linear_map∥ ≤ 1 := f.to_continuous_linear_map.op_norm_le_bound zero_le_one $ λ x, by simp end linear_isometry namespace linear_map /-- If a continuous linear map is constructed from a linear map via the constructor `mk_continuous`, then its norm is bounded by the bound given to the constructor if it is nonnegative. -/ lemma mk_continuous_norm_le (f : E →ₗ[𝕜] F) {C : ℝ} (hC : 0 ≤ C) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : ∥f.mk_continuous C h∥ ≤ C := continuous_linear_map.op_norm_le_bound _ hC h /-- If a continuous linear map is constructed from a linear map via the constructor `mk_continuous`, then its norm is bounded by the bound or zero if bound is negative. -/ lemma mk_continuous_norm_le' (f : E →ₗ[𝕜] F) {C : ℝ} (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : ∥f.mk_continuous C h∥ ≤ max C 0 := continuous_linear_map.op_norm_le_bound _ (le_max_right _ _) $ λ x, (h x).trans $ mul_le_mul_of_nonneg_right (le_max_left _ _) (norm_nonneg x) /-- Create a bilinear map (represented as a map `E →L[𝕜] F →L[𝕜] G`) from the corresponding linear map and a bound on the norm of the image. The linear map can be constructed using `linear_map.mk₂`. -/ def mk_continuous₂ (f : E →ₗ[𝕜] F →ₗ[𝕜] G) (C : ℝ) (hC : ∀ x y, ∥f x y∥ ≤ C * ∥x∥ * ∥y∥) : E →L[𝕜] F →L[𝕜] G := linear_map.mk_continuous { to_fun := λ x, (f x).mk_continuous (C * ∥x∥) (hC x), map_add' := λ x y, by { ext z, simp }, map_smul' := λ c x, by { ext z, simp } } (max C 0) $ λ x, (mk_continuous_norm_le' _ _).trans_eq $ by rw [max_mul_of_nonneg _ _ (norm_nonneg x), zero_mul] @[simp] lemma mk_continuous₂_apply (f : E →ₗ[𝕜] F →ₗ[𝕜] G) {C : ℝ} (hC : ∀ x y, ∥f x y∥ ≤ C * ∥x∥ * ∥y∥) (x : E) (y : F) : f.mk_continuous₂ C hC x y = f x y := rfl lemma mk_continuous₂_norm_le' (f : E →ₗ[𝕜] F →ₗ[𝕜] G) {C : ℝ} (hC : ∀ x y, ∥f x y∥ ≤ C * ∥x∥ * ∥y∥) : ∥f.mk_continuous₂ C hC∥ ≤ max C 0 := mk_continuous_norm_le _ (le_max_iff.2 $ or.inr le_rfl) _ lemma mk_continuous₂_norm_le (f : E →ₗ[𝕜] F →ₗ[𝕜] G) {C : ℝ} (h0 : 0 ≤ C) (hC : ∀ x y, ∥f x y∥ ≤ C * ∥x∥ * ∥y∥) : ∥f.mk_continuous₂ C hC∥ ≤ C := (f.mk_continuous₂_norm_le' hC).trans_eq $ max_eq_left h0 end linear_map namespace continuous_linear_map /-- Flip the order of arguments of a continuous bilinear map. For a version bundled as `linear_isometry_equiv`, see `continuous_linear_map.flipL`. -/ def flip (f : E →L[𝕜] F →L[𝕜] G) : F →L[𝕜] E →L[𝕜] G := linear_map.mk_continuous₂ (linear_map.mk₂ 𝕜 (λ y x, f x y) (λ x y z, (f z).map_add x y) (λ c y x, (f x).map_smul c y) (λ z x y, by rw [f.map_add, add_apply]) (λ c y x, by rw [map_smul, smul_apply])) ∥f∥ (λ y x, (f.le_op_norm₂ x y).trans_eq $ by rw mul_right_comm) private lemma le_norm_flip (f : E →L[𝕜] F →L[𝕜] G) : ∥f∥ ≤ ∥flip f∥ := f.op_norm_le_bound₂ (norm_nonneg _) $ λ x y, by { rw mul_right_comm, exact (flip f).le_op_norm₂ y x } @[simp] lemma flip_apply (f : E →L[𝕜] F →L[𝕜] G) (x : E) (y : F) : f.flip y x = f x y := rfl @[simp] lemma flip_flip (f : E →L[𝕜] F →L[𝕜] G) : f.flip.flip = f := by { ext, refl } @[simp] lemma op_norm_flip (f : E →L[𝕜] F →L[𝕜] G) : ∥f.flip∥ = ∥f∥ := le_antisymm (by simpa only [flip_flip] using le_norm_flip f.flip) (le_norm_flip f) @[simp] lemma flip_add (f g : E →L[𝕜] F →L[𝕜] G) : (f + g).flip = f.flip + g.flip := rfl @[simp] lemma flip_smul (c : 𝕜) (f : E →L[𝕜] F →L[𝕜] G) : (c • f).flip = c • f.flip := rfl variables (𝕜 E F G) /-- Flip the order of arguments of a continuous bilinear map. This is a version bundled as a `linear_isometry_equiv`. For an unbundled version see `continuous_linear_map.flip`. -/ def flipₗᵢ : (E →L[𝕜] F →L[𝕜] G) ≃ₗᵢ[𝕜] (F →L[𝕜] E →L[𝕜] G) := { to_fun := flip, inv_fun := flip, map_add' := flip_add, map_smul' := flip_smul, left_inv := flip_flip, right_inv := flip_flip, norm_map' := op_norm_flip } variables {𝕜 E F G} @[simp] lemma flipₗᵢ_symm : (flipₗᵢ 𝕜 E F G).symm = flipₗᵢ 𝕜 F E G := rfl @[simp] lemma coe_flipₗᵢ : ⇑(flipₗᵢ 𝕜 E F G) = flip := rfl variables (𝕜 F) /-- The continuous linear map obtained by applying a continuous linear map at a given vector. This is the continuous version of `linear_map.applyₗ`. -/ def apply : E →L[𝕜] (E →L[𝕜] F) →L[𝕜] F := flip (id 𝕜 (E →L[𝕜] F)) variables {𝕜 F} @[simp] lemma apply_apply (v : E) (f : E →L[𝕜] F) : apply 𝕜 F v f = f v := rfl variables (𝕜 E F G) /-- Composition of continuous linear maps as a continuous bilinear map. -/ def compL : (F →L[𝕜] G) →L[𝕜] (E →L[𝕜] F) →L[𝕜] (E →L[𝕜] G) := linear_map.mk_continuous₂ (linear_map.mk₂ _ comp add_comp smul_comp comp_add (λ c f g, comp_smul _ _ _)) 1 $ λ f g, by simpa only [one_mul] using op_norm_comp_le f g variables {𝕜 E F G} @[simp] lemma compL_apply (f : F →L[𝕜] G) (g : E →L[𝕜] F) : compL 𝕜 E F G f g = f.comp g := rfl section multiplication_linear variables (𝕜) (𝕜' : Type*) [normed_ring 𝕜'] [normed_algebra 𝕜 𝕜'] /-- Left multiplication in a normed algebra as a linear isometry to the space of continuous linear maps. -/ def lmulₗᵢ : 𝕜' →ₗᵢ[𝕜] 𝕜' →L[𝕜] 𝕜' := { to_linear_map := (algebra.lmul 𝕜 𝕜').to_linear_map.mk_continuous₂ 1 $ λ x y, by simpa using norm_mul_le x y, norm_map' := λ x, le_antisymm (op_norm_le_bound _ (norm_nonneg x) (norm_mul_le x)) (by { convert ratio_le_op_norm _ (1 : 𝕜'), simp [normed_algebra.norm_one 𝕜 𝕜'] }) } /-- Left multiplication in a normed algebra as a continuous bilinear map. -/ def lmul : 𝕜' →L[𝕜] 𝕜' →L[𝕜] 𝕜' := (lmulₗᵢ 𝕜 𝕜').to_continuous_linear_map @[simp] lemma lmul_apply (x y : 𝕜') : lmul 𝕜 𝕜' x y = x * y := rfl @[simp] lemma coe_lmulₗᵢ : ⇑(lmulₗᵢ 𝕜 𝕜') = lmul 𝕜 𝕜' := rfl @[simp] lemma op_norm_lmul_apply (x : 𝕜') : ∥lmul 𝕜 𝕜' x∥ = ∥x∥ := (lmulₗᵢ 𝕜 𝕜').norm_map x /-- Right-multiplication in a normed algebra, considered as a continuous linear map. -/ def lmul_right : 𝕜' →L[𝕜] 𝕜' →L[𝕜] 𝕜' := (lmul 𝕜 𝕜').flip @[simp] lemma lmul_right_apply (x y : 𝕜') : lmul_right 𝕜 𝕜' x y = y * x := rfl @[simp] lemma op_norm_lmul_right_apply (x : 𝕜') : ∥lmul_right 𝕜 𝕜' x∥ = ∥x∥ := le_antisymm (op_norm_le_bound _ (norm_nonneg x) (λ y, (norm_mul_le y x).trans_eq (mul_comm _ _))) (by { convert ratio_le_op_norm _ (1 : 𝕜'), simp [normed_algebra.norm_one 𝕜 𝕜'] }) /-- Right-multiplication in a normed algebra, considered as a linear isometry to the space of continuous linear maps. -/ def lmul_rightₗᵢ : 𝕜' →ₗᵢ[𝕜] 𝕜' →L[𝕜] 𝕜' := { to_linear_map := lmul_right 𝕜 𝕜', norm_map' := op_norm_lmul_right_apply 𝕜 𝕜' } @[simp] lemma coe_lmul_rightₗᵢ : ⇑(lmul_rightₗᵢ 𝕜 𝕜') = lmul_right 𝕜 𝕜' := rfl /-- Simultaneous left- and right-multiplication in a normed algebra, considered as a continuous trilinear map. -/ def lmul_left_right : 𝕜' →L[𝕜] 𝕜' →L[𝕜] 𝕜' →L[𝕜] 𝕜' := ((compL 𝕜 𝕜' 𝕜' 𝕜').comp (lmul_right 𝕜 𝕜')).flip.comp (lmul 𝕜 𝕜') @[simp] lemma lmul_left_right_apply (x y z : 𝕜') : lmul_left_right 𝕜 𝕜' x y z = x * z * y := rfl lemma op_norm_lmul_left_right_apply_apply_le (x y : 𝕜') : ∥lmul_left_right 𝕜 𝕜' x y∥ ≤ ∥x∥ * ∥y∥ := (op_norm_comp_le _ _).trans_eq $ by simp [mul_comm] lemma op_norm_lmul_left_right_apply_le (x : 𝕜') : ∥lmul_left_right 𝕜 𝕜' x∥ ≤ ∥x∥ := op_norm_le_bound _ (norm_nonneg x) (op_norm_lmul_left_right_apply_apply_le 𝕜 𝕜' x) lemma op_norm_lmul_left_right_le : ∥lmul_left_right 𝕜 𝕜'∥ ≤ 1 := op_norm_le_bound _ zero_le_one (λ x, (one_mul ∥x∥).symm ▸ op_norm_lmul_left_right_apply_le 𝕜 𝕜' x) end multiplication_linear section smul_linear variables (𝕜) (𝕜' : Type*) [normed_field 𝕜'] [normed_algebra 𝕜 𝕜'] [semi_normed_space 𝕜' E] [is_scalar_tower 𝕜 𝕜' E] /-- Scalar multiplication as a continuous bilinear map. -/ def lsmul : 𝕜' →L[𝕜] E →L[𝕜] E := ((algebra.lsmul 𝕜 E).to_linear_map : 𝕜' →ₗ[𝕜] E →ₗ[𝕜] E).mk_continuous₂ 1 $ λ c x, by simpa only [one_mul] using (norm_smul c x).le @[simp] lemma lsmul_apply (c : 𝕜') (x : E) : lsmul 𝕜 𝕜' c x = c • x := rfl end smul_linear section restrict_scalars variables {𝕜' : Type*} [nondiscrete_normed_field 𝕜'] [normed_algebra 𝕜' 𝕜] variables [semi_normed_space 𝕜' E] [is_scalar_tower 𝕜' 𝕜 E] variables [semi_normed_space 𝕜' F] [is_scalar_tower 𝕜' 𝕜 F] @[simp] lemma norm_restrict_scalars (f : E →L[𝕜] F) : ∥f.restrict_scalars 𝕜'∥ = ∥f∥ := le_antisymm (op_norm_le_bound _ (norm_nonneg _) $ λ x, f.le_op_norm x) (op_norm_le_bound _ (norm_nonneg _) $ λ x, f.le_op_norm x) variables (𝕜 E F 𝕜') (𝕜'' : Type*) [ring 𝕜''] [topological_space 𝕜''] [module 𝕜'' F] [has_continuous_smul 𝕜'' F] [smul_comm_class 𝕜 𝕜'' F] [smul_comm_class 𝕜' 𝕜'' F] /-- `continuous_linear_map.restrict_scalars` as a `linear_isometry`. -/ def restrict_scalars_isometry : (E →L[𝕜] F) →ₗᵢ[𝕜''] (E →L[𝕜'] F) := ⟨restrict_scalarsₗ 𝕜 E F 𝕜' 𝕜'', norm_restrict_scalars⟩ variables {𝕜 E F 𝕜' 𝕜''} @[simp] lemma coe_restrict_scalars_isometry : ⇑(restrict_scalars_isometry 𝕜 E F 𝕜' 𝕜'') = restrict_scalars 𝕜' := rfl @[simp] lemma restrict_scalars_isometry_to_linear_map : (restrict_scalars_isometry 𝕜 E F 𝕜' 𝕜'').to_linear_map = restrict_scalarsₗ 𝕜 E F 𝕜' 𝕜'' := rfl variables (𝕜 E F 𝕜' 𝕜'') /-- `continuous_linear_map.restrict_scalars` as a `continuous_linear_map`. -/ def restrict_scalarsL : (E →L[𝕜] F) →L[𝕜''] (E →L[𝕜'] F) := (restrict_scalars_isometry 𝕜 E F 𝕜' 𝕜'').to_continuous_linear_map variables {𝕜 E F 𝕜' 𝕜''} @[simp] lemma coe_restrict_scalarsL : (restrict_scalarsL 𝕜 E F 𝕜' 𝕜'' : (E →L[𝕜] F) →ₗ[𝕜''] (E →L[𝕜'] F)) = restrict_scalarsₗ 𝕜 E F 𝕜' 𝕜'' := rfl @[simp] lemma coe_restrict_scalarsL' : ⇑(restrict_scalarsL 𝕜 E F 𝕜' 𝕜'') = restrict_scalars 𝕜' := rfl end restrict_scalars end continuous_linear_map namespace submodule lemma norm_subtypeL_le (K : submodule 𝕜 E) : ∥K.subtypeL∥ ≤ 1 := K.subtypeₗᵢ.norm_to_continuous_linear_map_le end submodule section has_sum -- Results in this section hold for continuous additive monoid homomorphisms or equivalences but we -- don't have bundled continuous additive homomorphisms. variables {ι R M M₂ : Type*} [semiring R] [add_comm_monoid M] [module R M] [add_comm_monoid M₂] [module R M₂] [topological_space M] [topological_space M₂] omit 𝕜 /-- Applying a continuous linear map commutes with taking an (infinite) sum. -/ protected lemma continuous_linear_map.has_sum {f : ι → M} (φ : M →L[R] M₂) {x : M} (hf : has_sum f x) : has_sum (λ (b:ι), φ (f b)) (φ x) := by simpa only using hf.map φ.to_linear_map.to_add_monoid_hom φ.continuous alias continuous_linear_map.has_sum ← has_sum.mapL protected lemma continuous_linear_map.summable {f : ι → M} (φ : M →L[R] M₂) (hf : summable f) : summable (λ b:ι, φ (f b)) := (hf.has_sum.mapL φ).summable alias continuous_linear_map.summable ← summable.mapL protected lemma continuous_linear_map.map_tsum [t2_space M₂] {f : ι → M} (φ : M →L[R] M₂) (hf : summable f) : φ (∑' z, f z) = ∑' z, φ (f z) := (hf.has_sum.mapL φ).tsum_eq.symm /-- Applying a continuous linear map commutes with taking an (infinite) sum. -/ protected lemma continuous_linear_equiv.has_sum {f : ι → M} (e : M ≃L[R] M₂) {y : M₂} : has_sum (λ (b:ι), e (f b)) y ↔ has_sum f (e.symm y) := ⟨λ h, by simpa only [e.symm.coe_coe, e.symm_apply_apply] using h.mapL (e.symm : M₂ →L[R] M), λ h, by simpa only [e.coe_coe, e.apply_symm_apply] using (e : M →L[R] M₂).has_sum h⟩ protected lemma continuous_linear_equiv.summable {f : ι → M} (e : M ≃L[R] M₂) : summable (λ b:ι, e (f b)) ↔ summable f := ⟨λ hf, (e.has_sum.1 hf.has_sum).summable, (e : M →L[R] M₂).summable⟩ lemma continuous_linear_equiv.tsum_eq_iff [t2_space M] [t2_space M₂] {f : ι → M} (e : M ≃L[R] M₂) {y : M₂} : ∑' z, e (f z) = y ↔ ∑' z, f z = e.symm y := begin by_cases hf : summable f, { exact ⟨λ h, (e.has_sum.mp ((e.summable.mpr hf).has_sum_iff.mpr h)).tsum_eq, λ h, (e.has_sum.mpr (hf.has_sum_iff.mpr h)).tsum_eq⟩ }, { have hf' : ¬summable (λ z, e (f z)) := λ h, hf (e.summable.mp h), rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hf'], exact ⟨by { rintro rfl, simp }, λ H, by simpa using (congr_arg (λ z, e z) H)⟩ } end protected lemma continuous_linear_equiv.map_tsum [t2_space M] [t2_space M₂] {f : ι → M} (e : M ≃L[R] M₂) : e (∑' z, f z) = ∑' z, e (f z) := by { refine symm (e.tsum_eq_iff.mpr _), rw e.symm_apply_apply _ } end has_sum namespace continuous_linear_equiv variables (e : E ≃L[𝕜] F) protected lemma lipschitz : lipschitz_with (∥(e : E →L[𝕜] F)∥₊) e := (e : E →L[𝕜] F).lipschitz theorem is_O_comp {α : Type*} (f : α → E) (l : filter α) : asymptotics.is_O (λ x', e (f x')) f l := (e : E →L[𝕜] F).is_O_comp f l theorem is_O_sub (l : filter E) (x : E) : asymptotics.is_O (λ x', e (x' - x)) (λ x', x' - x) l := (e : E →L[𝕜] F).is_O_sub l x theorem is_O_comp_rev {α : Type*} (f : α → E) (l : filter α) : asymptotics.is_O f (λ x', e (f x')) l := (e.symm.is_O_comp _ l).congr_left $ λ _, e.symm_apply_apply _ theorem is_O_sub_rev (l : filter E) (x : E) : asymptotics.is_O (λ x', x' - x) (λ x', e (x' - x)) l := e.is_O_comp_rev _ _ lemma homothety_inverse (a : ℝ) (ha : 0 < a) (f : E ≃ₗ[𝕜] F) : (∀ (x : E), ∥f x∥ = a * ∥x∥) → (∀ (y : F), ∥f.symm y∥ = a⁻¹ * ∥y∥) := begin intros hf y, calc ∥(f.symm) y∥ = a⁻¹ * (a * ∥ (f.symm) y∥) : _ ... = a⁻¹ * ∥f ((f.symm) y)∥ : by rw hf ... = a⁻¹ * ∥y∥ : by simp, rw [← mul_assoc, inv_mul_cancel (ne_of_lt ha).symm, one_mul], end /-- A linear equivalence which is a homothety is a continuous linear equivalence. -/ def of_homothety (f : E ≃ₗ[𝕜] F) (a : ℝ) (ha : 0 < a) (hf : ∀x, ∥f x∥ = a * ∥x∥) : E ≃L[𝕜] F := { to_linear_equiv := f, continuous_to_fun := f.to_linear_map.continuous_of_bound a (λ x, le_of_eq (hf x)), continuous_inv_fun := f.symm.to_linear_map.continuous_of_bound a⁻¹ (λ x, le_of_eq (homothety_inverse a ha f hf x)) } variable (𝕜) lemma to_span_nonzero_singleton_homothety (x : E) (h : x ≠ 0) (c : 𝕜) : ∥linear_equiv.to_span_nonzero_singleton 𝕜 E x h c∥ = ∥x∥ * ∥c∥ := continuous_linear_map.to_span_singleton_homothety _ _ _ end continuous_linear_equiv /-- Construct a continuous linear equivalence from a linear equivalence together with bounds in both directions. -/ def linear_equiv.to_continuous_linear_equiv_of_bounds (e : E ≃ₗ[𝕜] F) (C_to C_inv : ℝ) (h_to : ∀ x, ∥e x∥ ≤ C_to * ∥x∥) (h_inv : ∀ x : F, ∥e.symm x∥ ≤ C_inv * ∥x∥) : E ≃L[𝕜] F := { to_linear_equiv := e, continuous_to_fun := e.to_linear_map.continuous_of_bound C_to h_to, continuous_inv_fun := e.symm.to_linear_map.continuous_of_bound C_inv h_inv } namespace continuous_linear_map variables (𝕜) (𝕜' : Type*) [normed_ring 𝕜'] [normed_algebra 𝕜 𝕜'] variables {𝕜} variables {E' F' : Type*} [semi_normed_group E'] [semi_normed_group F'] [semi_normed_space 𝕜 E'] [semi_normed_space 𝕜 F'] /-- Compose a bilinear map `E →L[𝕜] F →L[𝕜] G` with two linear maps `E' →L[𝕜] E` and `F' →L[𝕜] F`. -/ def bilinear_comp (f : E →L[𝕜] F →L[𝕜] G) (gE : E' →L[𝕜] E) (gF : F' →L[𝕜] F) : E' →L[𝕜] F' →L[𝕜] G := ((f.comp gE).flip.comp gF).flip @[simp] lemma bilinear_comp_apply (f : E →L[𝕜] F →L[𝕜] G) (gE : E' →L[𝕜] E) (gF : F' →L[𝕜] F) (x : E') (y : F') : f.bilinear_comp gE gF x y = f (gE x) (gF y) := rfl /-- Derivative of a continuous bilinear map `f : E →L[𝕜] F →L[𝕜] G` interpreted as a map `E × F → G` at point `p : E × F` evaluated at `q : E × F`, as a continuous bilinear map. -/ def deriv₂ (f : E →L[𝕜] F →L[𝕜] G) : (E × F) →L[𝕜] (E × F) →L[𝕜] G := f.bilinear_comp (fst _ _ _) (snd _ _ _) + f.flip.bilinear_comp (snd _ _ _) (fst _ _ _) @[simp] lemma coe_deriv₂ (f : E →L[𝕜] F →L[𝕜] G) (p : E × F) : ⇑(f.deriv₂ p) = λ q : E × F, f p.1 q.2 + f q.1 p.2 := rfl lemma map_add₂ (f : E →L[𝕜] F →L[𝕜] G) (x x' : E) (y y' : F) : f (x + x') (y + y') = f x y + f.deriv₂ (x, y) (x', y') + f x' y' := by simp only [map_add, add_apply, coe_deriv₂, add_assoc] end continuous_linear_map end semi_normed section normed variables [normed_group E] [normed_group F] [normed_group G] open metric continuous_linear_map section normed_field variables [normed_field 𝕜] [normed_space 𝕜 E] [normed_space 𝕜 F] (f : E →ₗ[𝕜] F) lemma linear_map.continuous_iff_is_closed_ker {f : E →ₗ[𝕜] 𝕜} : continuous f ↔ is_closed (f.ker : set E) := begin -- the continuity of f obviously implies that its kernel is closed refine ⟨λh, (t1_space.t1 (0 : 𝕜)).preimage h, λh, _⟩, -- for the other direction, we assume that the kernel is closed by_cases hf : ∀x, x ∈ f.ker, { -- if `f = 0`, its continuity is obvious have : (f : E → 𝕜) = (λx, 0), by { ext x, simpa using hf x }, rw this, exact continuous_const }, { /- if `f` is not zero, we use an element `x₀ ∉ ker f` such that `∥x₀∥ ≤ 2 ∥x₀ - y∥` for all `y ∈ ker f`, given by Riesz's lemma, and prove that `2 ∥f x₀∥ / ∥x₀∥` gives a bound on the operator norm of `f`. For this, start from an arbitrary `x` and note that `y = x₀ - (f x₀ / f x) x` belongs to the kernel of `f`. Applying the above inequality to `x₀` and `y` readily gives the conclusion. -/ push_neg at hf, let r : ℝ := (2 : ℝ)⁻¹, have : 0 ≤ r, by norm_num [r], have : r < 1, by norm_num [r], obtain ⟨x₀, x₀ker, h₀⟩ : ∃ (x₀ : E), x₀ ∉ f.ker ∧ ∀ y ∈ linear_map.ker f, r * ∥x₀∥ ≤ ∥x₀ - y∥, from riesz_lemma h hf this, have : x₀ ≠ 0, { assume h, have : x₀ ∈ f.ker, by { rw h, exact (linear_map.ker f).zero_mem }, exact x₀ker this }, have rx₀_ne_zero : r * ∥x₀∥ ≠ 0, by { simp [norm_eq_zero, this], }, have : ∀x, ∥f x∥ ≤ (((r * ∥x₀∥)⁻¹) * ∥f x₀∥) * ∥x∥, { assume x, by_cases hx : f x = 0, { rw [hx, norm_zero], apply_rules [mul_nonneg, norm_nonneg, inv_nonneg.2] }, { let y := x₀ - (f x₀ * (f x)⁻¹ ) • x, have fy_zero : f y = 0, by calc f y = f x₀ - (f x₀ * (f x)⁻¹ ) * f x : by simp [y] ... = 0 : by { rw [mul_assoc, inv_mul_cancel hx, mul_one, sub_eq_zero_of_eq], refl }, have A : r * ∥x₀∥ ≤ ∥f x₀∥ * ∥f x∥⁻¹ * ∥x∥, from calc r * ∥x₀∥ ≤ ∥x₀ - y∥ : h₀ _ (linear_map.mem_ker.2 fy_zero) ... = ∥(f x₀ * (f x)⁻¹ ) • x∥ : by { dsimp [y], congr, abel } ... = ∥f x₀∥ * ∥f x∥⁻¹ * ∥x∥ : by rw [norm_smul, normed_field.norm_mul, normed_field.norm_inv], calc ∥f x∥ = (r * ∥x₀∥)⁻¹ * (r * ∥x₀∥) * ∥f x∥ : by rwa [inv_mul_cancel, one_mul] ... ≤ (r * ∥x₀∥)⁻¹ * (∥f x₀∥ * ∥f x∥⁻¹ * ∥x∥) * ∥f x∥ : begin apply mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left A _) (norm_nonneg _), exact inv_nonneg.2 (mul_nonneg (by norm_num) (norm_nonneg _)) end ... = (∥f x∥ ⁻¹ * ∥f x∥) * (((r * ∥x₀∥)⁻¹) * ∥f x₀∥) * ∥x∥ : by ring ... = (((r * ∥x₀∥)⁻¹) * ∥f x₀∥) * ∥x∥ : by { rw [inv_mul_cancel, one_mul], simp [norm_eq_zero, hx] } } }, exact linear_map.continuous_of_bound f _ this } end end normed_field variables [nondiscrete_normed_field 𝕜] [normed_space 𝕜 E] [normed_space 𝕜 F] [normed_space 𝕜 G] (c : 𝕜) (f g : E →L[𝕜] F) (h : F →L[𝕜] G) (x y z : E) include 𝕜 lemma linear_map.bound_of_shell (f : E →ₗ[𝕜] F) {ε C : ℝ} (ε_pos : 0 < ε) {c : 𝕜} (hc : 1 < ∥c∥) (hf : ∀ x, ε / ∥c∥ ≤ ∥x∥ → ∥x∥ < ε → ∥f x∥ ≤ C * ∥x∥) (x : E) : ∥f x∥ ≤ C * ∥x∥ := begin by_cases hx : x = 0, { simp [hx] }, exact linear_map.bound_of_shell_semi_normed f ε_pos hc hf (ne_of_lt (norm_pos_iff.2 hx)).symm end namespace continuous_linear_map section op_norm open set real /-- An operator is zero iff its norm vanishes. -/ theorem op_norm_zero_iff : ∥f∥ = 0 ↔ f = 0 := iff.intro (λ hn, continuous_linear_map.ext (λ x, norm_le_zero_iff.1 (calc _ ≤ ∥f∥ * ∥x∥ : le_op_norm _ _ ... = _ : by rw [hn, zero_mul]))) (λ hf, le_antisymm (cInf_le bounds_bdd_below ⟨le_rfl, λ _, le_of_eq (by { rw [zero_mul, hf], exact norm_zero })⟩) (op_norm_nonneg _)) /-- If a normed space is non-trivial, then the norm of the identity equals `1`. -/ @[simp] lemma norm_id [nontrivial E] : ∥id 𝕜 E∥ = 1 := begin refine norm_id_of_nontrivial_seminorm _, obtain ⟨x, hx⟩ := exists_ne (0 : E), exact ⟨x, ne_of_gt (norm_pos_iff.2 hx)⟩, end instance norm_one_class [nontrivial E] : norm_one_class (E →L[𝕜] E) := ⟨norm_id⟩ /-- Continuous linear maps themselves form a normed space with respect to the operator norm. -/ instance to_normed_group : normed_group (E →L[𝕜] F) := normed_group.of_core _ ⟨op_norm_zero_iff, op_norm_add_le, op_norm_neg⟩ instance to_normed_space {𝕜' : Type*} [normed_field 𝕜'] [normed_space 𝕜' F] [smul_comm_class 𝕜 𝕜' F] : normed_space 𝕜' (E →L[𝕜] F) := ⟨op_norm_smul_le⟩ /-- Continuous linear maps form a normed ring with respect to the operator norm. -/ instance to_normed_ring : normed_ring (E →L[𝕜] E) := { norm_mul := op_norm_comp_le, .. continuous_linear_map.to_normed_group } /-- For a nonzero normed space `E`, continuous linear endomorphisms form a normed algebra with respect to the operator norm. -/ instance to_normed_algebra [nontrivial E] : normed_algebra 𝕜 (E →L[𝕜] E) := { norm_algebra_map_eq := λ c, show ∥c • id 𝕜 E∥ = ∥c∥, by {rw [norm_smul, norm_id], simp}, .. continuous_linear_map.algebra } variable {f} lemma homothety_norm [nontrivial E] (f : E →L[𝕜] F) {a : ℝ} (hf : ∀x, ∥f x∥ = a * ∥x∥) : ∥f∥ = a := begin obtain ⟨x, hx⟩ : ∃ (x : E), x ≠ 0 := exists_ne 0, rw ← norm_pos_iff at hx, have ha : 0 ≤ a, by simpa only [hf, hx, zero_le_mul_right] using norm_nonneg (f x), apply le_antisymm (f.op_norm_le_bound ha (λ y, le_of_eq (hf y))), simpa only [hf, hx, mul_le_mul_right] using f.le_op_norm x, end lemma to_span_singleton_norm (x : E) : ∥to_span_singleton 𝕜 x∥ = ∥x∥ := homothety_norm _ (to_span_singleton_homothety 𝕜 x) variable (f) theorem uniform_embedding_of_bound {K : ℝ≥0} (hf : ∀ x, ∥x∥ ≤ K * ∥f x∥) : uniform_embedding f := (f.to_linear_map.antilipschitz_of_bound hf).uniform_embedding f.uniform_continuous /-- If a continuous linear map is a uniform embedding, then it is expands the distances by a positive factor.-/ theorem antilipschitz_of_uniform_embedding (hf : uniform_embedding f) : ∃ K, antilipschitz_with K f := begin obtain ⟨ε, εpos, hε⟩ : ∃ (ε : ℝ) (H : ε > 0), ∀ {x y : E}, dist (f x) (f y) < ε → dist x y < 1, from (uniform_embedding_iff.1 hf).2.2 1 zero_lt_one, let δ := ε/2, have δ_pos : δ > 0 := half_pos εpos, have H : ∀{x}, ∥f x∥ ≤ δ → ∥x∥ ≤ 1, { assume x hx, have : dist x 0 ≤ 1, { refine (hε _).le, rw [f.map_zero, dist_zero_right], exact hx.trans_lt (half_lt_self εpos) }, simpa using this }, rcases normed_field.exists_one_lt_norm 𝕜 with ⟨c, hc⟩, refine ⟨⟨δ⁻¹, _⟩ * nnnorm c, f.to_linear_map.antilipschitz_of_bound $ λx, _⟩, exact inv_nonneg.2 (le_of_lt δ_pos), by_cases hx : f x = 0, { have : f x = f 0, by { simp [hx] }, have : x = 0 := (uniform_embedding_iff.1 hf).1 this, simp [this] }, { rcases rescale_to_shell hc δ_pos hx with ⟨d, hd, dxlt, ledx, dinv⟩, rw [← f.map_smul d] at dxlt, have : ∥d • x∥ ≤ 1 := H dxlt.le, calc ∥x∥ = ∥d∥⁻¹ * ∥d • x∥ : by rwa [← normed_field.norm_inv, ← norm_smul, ← mul_smul, inv_mul_cancel, one_smul] ... ≤ ∥d∥⁻¹ * 1 : mul_le_mul_of_nonneg_left this (inv_nonneg.2 (norm_nonneg _)) ... ≤ δ⁻¹ * ∥c∥ * ∥f x∥ : by rwa [mul_one] } end section completeness open_locale topological_space open filter /-- If the target space is complete, the space of continuous linear maps with its norm is also complete. This works also if the source space is seminormed. -/ instance {E : Type*} [semi_normed_group E] [semi_normed_space 𝕜 E] [complete_space F] : complete_space (E →L[𝕜] F) := begin -- We show that every Cauchy sequence converges. refine metric.complete_of_cauchy_seq_tendsto (λ f hf, _), -- We now expand out the definition of a Cauchy sequence, rcases cauchy_seq_iff_le_tendsto_0.1 hf with ⟨b, b0, b_bound, b_lim⟩, clear hf, -- and establish that the evaluation at any point `v : E` is Cauchy. have cau : ∀ v, cauchy_seq (λ n, f n v), { assume v, apply cauchy_seq_iff_le_tendsto_0.2 ⟨λ n, b n * ∥v∥, λ n, _, _, _⟩, { exact mul_nonneg (b0 n) (norm_nonneg _) }, { assume n m N hn hm, rw dist_eq_norm, apply le_trans ((f n - f m).le_op_norm v) _, exact mul_le_mul_of_nonneg_right (b_bound n m N hn hm) (norm_nonneg v) }, { simpa using b_lim.mul tendsto_const_nhds } }, -- We assemble the limits points of those Cauchy sequences -- (which exist as `F` is complete) -- into a function which we call `G`. choose G hG using λv, cauchy_seq_tendsto_of_complete (cau v), -- Next, we show that this `G` is linear, let Glin : E →ₗ[𝕜] F := { to_fun := G, map_add' := λ v w, begin have A := hG (v + w), have B := (hG v).add (hG w), simp only [map_add] at A B, exact tendsto_nhds_unique A B, end, map_smul' := λ c v, begin have A := hG (c • v), have B := filter.tendsto.smul (@tendsto_const_nhds _ ℕ _ c _) (hG v), simp only [map_smul] at A B, exact tendsto_nhds_unique A B end }, -- and that `G` has norm at most `(b 0 + ∥f 0∥)`. have Gnorm : ∀ v, ∥G v∥ ≤ (b 0 + ∥f 0∥) * ∥v∥, { assume v, have A : ∀ n, ∥f n v∥ ≤ (b 0 + ∥f 0∥) * ∥v∥, { assume n, apply le_trans ((f n).le_op_norm _) _, apply mul_le_mul_of_nonneg_right _ (norm_nonneg v), calc ∥f n∥ = ∥(f n - f 0) + f 0∥ : by { congr' 1, abel } ... ≤ ∥f n - f 0∥ + ∥f 0∥ : norm_add_le _ _ ... ≤ b 0 + ∥f 0∥ : begin apply add_le_add_right, simpa [dist_eq_norm] using b_bound n 0 0 (zero_le _) (zero_le _) end }, exact le_of_tendsto (hG v).norm (eventually_of_forall A) }, -- Thus `G` is continuous, and we propose that as the limit point of our original Cauchy sequence. let Gcont := Glin.mk_continuous _ Gnorm, use Gcont, -- Our last task is to establish convergence to `G` in norm. have : ∀ n, ∥f n - Gcont∥ ≤ b n, { assume n, apply op_norm_le_bound _ (b0 n) (λ v, _), have A : ∀ᶠ m in at_top, ∥(f n - f m) v∥ ≤ b n * ∥v∥, { refine eventually_at_top.2 ⟨n, λ m hm, _⟩, apply le_trans ((f n - f m).le_op_norm _) _, exact mul_le_mul_of_nonneg_right (b_bound n m n (le_refl _) hm) (norm_nonneg v) }, have B : tendsto (λ m, ∥(f n - f m) v∥) at_top (𝓝 (∥(f n - Gcont) v∥)) := tendsto.norm (tendsto_const_nhds.sub (hG v)), exact le_of_tendsto B A }, erw tendsto_iff_norm_tendsto_zero, exact squeeze_zero (λ n, norm_nonneg _) this b_lim, end end completeness section uniformly_extend variables [complete_space F] (e : E →L[𝕜] G) (h_dense : dense_range e) section variables (h_e : uniform_inducing e) /-- Extension of a continuous linear map `f : E →L[𝕜] F`, with `E` a normed space and `F` a complete normed space, along a uniform and dense embedding `e : E →L[𝕜] G`. -/ def extend : G →L[𝕜] F := /- extension of `f` is continuous -/ have cont : _ := (uniform_continuous_uniformly_extend h_e h_dense f.uniform_continuous).continuous, /- extension of `f` agrees with `f` on the domain of the embedding `e` -/ have eq : _ := uniformly_extend_of_ind h_e h_dense f.uniform_continuous, { to_fun := (h_e.dense_inducing h_dense).extend f, map_add' := begin refine h_dense.induction_on₂ _ _, { exact is_closed_eq (cont.comp continuous_add) ((cont.comp continuous_fst).add (cont.comp continuous_snd)) }, { assume x y, simp only [eq, ← e.map_add], exact f.map_add _ _ }, end, map_smul' := λk, begin refine (λ b, h_dense.induction_on b _ _), { exact is_closed_eq (cont.comp (continuous_const.smul continuous_id)) ((continuous_const.smul continuous_id).comp cont) }, { assume x, rw ← map_smul, simp only [eq], exact map_smul _ _ _ }, end, cont := cont } lemma extend_unique (g : G →L[𝕜] F) (H : g.comp e = f) : extend f e h_dense h_e = g := continuous_linear_map.coe_fn_injective $ uniformly_extend_unique h_e h_dense (continuous_linear_map.ext_iff.1 H) g.continuous @[simp] lemma extend_zero : extend (0 : E →L[𝕜] F) e h_dense h_e = 0 := extend_unique _ _ _ _ _ (zero_comp _) end section variables {N : ℝ≥0} (h_e : ∀x, ∥x∥ ≤ N * ∥e x∥) local notation `ψ` := f.extend e h_dense (uniform_embedding_of_bound _ h_e).to_uniform_inducing /-- If a dense embedding `e : E →L[𝕜] G` expands the norm by a constant factor `N⁻¹`, then the norm of the extension of `f` along `e` is bounded by `N * ∥f∥`. -/ lemma op_norm_extend_le : ∥ψ∥ ≤ N * ∥f∥ := begin have uni : uniform_inducing e := (uniform_embedding_of_bound _ h_e).to_uniform_inducing, have eq : ∀x, ψ (e x) = f x := uniformly_extend_of_ind uni h_dense f.uniform_continuous, by_cases N0 : 0 ≤ N, { refine op_norm_le_bound ψ _ (is_closed_property h_dense (is_closed_le _ _) _), { exact mul_nonneg N0 (norm_nonneg _) }, { exact continuous_norm.comp (cont ψ) }, { exact continuous_const.mul continuous_norm }, { assume x, rw eq, calc ∥f x∥ ≤ ∥f∥ * ∥x∥ : le_op_norm _ _ ... ≤ ∥f∥ * (N * ∥e x∥) : mul_le_mul_of_nonneg_left (h_e x) (norm_nonneg _) ... ≤ N * ∥f∥ * ∥e x∥ : by rw [mul_comm ↑N ∥f∥, mul_assoc] } }, { have he : ∀ x : E, x = 0, { assume x, have N0 : N ≤ 0 := le_of_lt (lt_of_not_ge N0), rw ← norm_le_zero_iff, exact le_trans (h_e x) (mul_nonpos_of_nonpos_of_nonneg N0 (norm_nonneg _)) }, have hf : f = 0, { ext, simp only [he x, zero_apply, map_zero] }, have hψ : ψ = 0, { rw hf, apply extend_zero }, rw [hψ, hf, norm_zero, norm_zero, mul_zero] } end end end uniformly_extend end op_norm end continuous_linear_map namespace linear_isometry @[simp] lemma norm_to_continuous_linear_map [nontrivial E] (f : E →ₗᵢ[𝕜] F) : ∥f.to_continuous_linear_map∥ = 1 := f.to_continuous_linear_map.homothety_norm $ by simp end linear_isometry namespace continuous_linear_map /-- Precomposition with a linear isometry preserves the operator norm. -/ lemma op_norm_comp_linear_isometry_equiv {G : Type*} [semi_normed_group G] [semi_normed_space 𝕜 G] (f : F →L[𝕜] G) (g : E ≃ₗᵢ[𝕜] F) : ∥f.comp g.to_linear_isometry.to_continuous_linear_map∥ = ∥f∥ := begin casesI subsingleton_or_nontrivial E, { haveI := g.symm.to_linear_equiv.to_equiv.subsingleton, simp }, refine le_antisymm _ _, { convert f.op_norm_comp_le g.to_linear_isometry.to_continuous_linear_map, simp [g.to_linear_isometry.norm_to_continuous_linear_map] }, { convert (f.comp g.to_linear_isometry.to_continuous_linear_map).op_norm_comp_le g.symm.to_linear_isometry.to_continuous_linear_map, { ext, simp }, haveI := g.symm.to_linear_equiv.to_equiv.nontrivial, simp [g.symm.to_linear_isometry.norm_to_continuous_linear_map] }, end /-- The norm of the tensor product of a scalar linear map and of an element of a normed space is the product of the norms. -/ @[simp] lemma norm_smul_right_apply (c : E →L[𝕜] 𝕜) (f : F) : ∥smul_right c f∥ = ∥c∥ * ∥f∥ := begin refine le_antisymm _ _, { apply op_norm_le_bound _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) (λx, _), calc ∥(c x) • f∥ = ∥c x∥ * ∥f∥ : norm_smul _ _ ... ≤ (∥c∥ * ∥x∥) * ∥f∥ : mul_le_mul_of_nonneg_right (le_op_norm _ _) (norm_nonneg _) ... = ∥c∥ * ∥f∥ * ∥x∥ : by ring }, { by_cases h : f = 0, { simp [h] }, { have : 0 < ∥f∥ := norm_pos_iff.2 h, rw ← le_div_iff this, apply op_norm_le_bound _ (div_nonneg (norm_nonneg _) (norm_nonneg f)) (λx, _), rw [div_mul_eq_mul_div, le_div_iff this], calc ∥c x∥ * ∥f∥ = ∥c x • f∥ : (norm_smul _ _).symm ... = ∥smul_right c f x∥ : rfl ... ≤ ∥smul_right c f∥ * ∥x∥ : le_op_norm _ _ } }, end /-- The non-negative norm of the tensor product of a scalar linear map and of an element of a normed space is the product of the non-negative norms. -/ @[simp] lemma nnnorm_smul_right_apply (c : E →L[𝕜] 𝕜) (f : F) : ∥smul_right c f∥₊ = ∥c∥₊ * ∥f∥₊ := nnreal.eq $ c.norm_smul_right_apply f variables (𝕜 E F) /-- `continuous_linear_map.smul_right` as a continuous trilinear map: `smul_rightL (c : E →L[𝕜] 𝕜) (f : F) (x : E) = c x • f`. -/ def smul_rightL : (E →L[𝕜] 𝕜) →L[𝕜] F →L[𝕜] E →L[𝕜] F := linear_map.mk_continuous₂ { to_fun := smul_rightₗ, map_add' := λ c₁ c₂, by { ext x, simp [add_smul] }, map_smul' := λ m c, by { ext x, simp [smul_smul] } } 1 $ λ c x, by simp variables {𝕜 E F} @[simp] lemma norm_smul_rightL_apply (c : E →L[𝕜] 𝕜) (f : F) : ∥smul_rightL 𝕜 E F c f∥ = ∥c∥ * ∥f∥ := norm_smul_right_apply c f @[simp] lemma norm_smul_rightL (c : E →L[𝕜] 𝕜) [nontrivial F] : ∥smul_rightL 𝕜 E F c∥ = ∥c∥ := continuous_linear_map.homothety_norm _ c.norm_smul_right_apply variables (𝕜) (𝕜' : Type*) [normed_ring 𝕜'] [normed_algebra 𝕜 𝕜'] @[simp] lemma op_norm_lmul : ∥lmul 𝕜 𝕜'∥ = 1 := by haveI := normed_algebra.nontrivial 𝕜 𝕜'; exact (lmulₗᵢ 𝕜 𝕜').norm_to_continuous_linear_map @[simp] lemma op_norm_lmul_right : ∥lmul_right 𝕜 𝕜'∥ = 1 := (op_norm_flip (@lmul 𝕜 _ 𝕜' _ _)).trans (op_norm_lmul _ _) end continuous_linear_map namespace submodule lemma norm_subtypeL (K : submodule 𝕜 E) [nontrivial K] : ∥K.subtypeL∥ = 1 := K.subtypeₗᵢ.norm_to_continuous_linear_map end submodule namespace continuous_linear_equiv variables (e : E ≃L[𝕜] F) protected lemma antilipschitz : antilipschitz_with (nnnorm (e.symm : F →L[𝕜] E)) e := e.symm.lipschitz.to_right_inverse e.left_inv /-- A continuous linear equiv is a uniform embedding. -/ lemma uniform_embedding : uniform_embedding e := e.antilipschitz.uniform_embedding e.lipschitz.uniform_continuous lemma one_le_norm_mul_norm_symm [nontrivial E] : 1 ≤ ∥(e : E →L[𝕜] F)∥ * ∥(e.symm : F →L[𝕜] E)∥ := begin rw [mul_comm], convert (e.symm : F →L[𝕜] E).op_norm_comp_le (e : E →L[𝕜] F), rw [e.coe_symm_comp_coe, continuous_linear_map.norm_id] end lemma norm_pos [nontrivial E] : 0 < ∥(e : E →L[𝕜] F)∥ := pos_of_mul_pos_right (lt_of_lt_of_le zero_lt_one e.one_le_norm_mul_norm_symm) (norm_nonneg _) lemma norm_symm_pos [nontrivial E] : 0 < ∥(e.symm : F →L[𝕜] E)∥ := pos_of_mul_pos_left (lt_of_lt_of_le zero_lt_one e.one_le_norm_mul_norm_symm) (norm_nonneg _) lemma nnnorm_symm_pos [nontrivial E] : 0 < nnnorm (e.symm : F →L[𝕜] E) := e.norm_symm_pos lemma subsingleton_or_norm_symm_pos : subsingleton E ∨ 0 < ∥(e.symm : F →L[𝕜] E)∥ := begin rcases subsingleton_or_nontrivial E with _i|_i; resetI, { left, apply_instance }, { right, exact e.norm_symm_pos } end lemma subsingleton_or_nnnorm_symm_pos : subsingleton E ∨ 0 < (nnnorm $ (e.symm : F →L[𝕜] E)) := subsingleton_or_norm_symm_pos e variable (𝕜) /-- Given a nonzero element `x` of a normed space `E₁` over a field `𝕜`, the natural continuous linear equivalence from `E₁` to the span of `x`.-/ def to_span_nonzero_singleton (x : E) (h : x ≠ 0) : 𝕜 ≃L[𝕜] (𝕜 ∙ x) := of_homothety (linear_equiv.to_span_nonzero_singleton 𝕜 E x h) ∥x∥ (norm_pos_iff.mpr h) (to_span_nonzero_singleton_homothety 𝕜 x h) /-- Given a nonzero element `x` of a normed space `E₁` over a field `𝕜`, the natural continuous linear map from the span of `x` to `𝕜`.-/ def coord (x : E) (h : x ≠ 0) : (𝕜 ∙ x) →L[𝕜] 𝕜 := (to_span_nonzero_singleton 𝕜 x h).symm @[simp] lemma coe_to_span_nonzero_singleton_symm {x : E} (h : x ≠ 0) : ⇑(to_span_nonzero_singleton 𝕜 x h).symm = coord 𝕜 x h := rfl @[simp] lemma coord_to_span_nonzero_singleton {x : E} (h : x ≠ 0) (c : 𝕜) : coord 𝕜 x h (to_span_nonzero_singleton 𝕜 x h c) = c := (to_span_nonzero_singleton 𝕜 x h).symm_apply_apply c @[simp] lemma to_span_nonzero_singleton_coord {x : E} (h : x ≠ 0) (y : 𝕜 ∙ x) : to_span_nonzero_singleton 𝕜 x h (coord 𝕜 x h y) = y := (to_span_nonzero_singleton 𝕜 x h).apply_symm_apply y @[simp] lemma coord_norm (x : E) (h : x ≠ 0) : ∥coord 𝕜 x h∥ = ∥x∥⁻¹ := begin have hx : 0 < ∥x∥ := (norm_pos_iff.mpr h), haveI : nontrivial (𝕜 ∙ x) := submodule.nontrivial_span_singleton h, exact continuous_linear_map.homothety_norm _ (λ y, homothety_inverse _ hx _ (to_span_nonzero_singleton_homothety 𝕜 x h) _) end @[simp] lemma coord_self (x : E) (h : x ≠ 0) : (coord 𝕜 x h) (⟨x, submodule.mem_span_singleton_self x⟩ : 𝕜 ∙ x) = 1 := linear_equiv.coord_self 𝕜 E x h end continuous_linear_equiv lemma linear_equiv.uniform_embedding (e : E ≃ₗ[𝕜] F) (h₁ : continuous e) (h₂ : continuous e.symm) : uniform_embedding e := continuous_linear_equiv.uniform_embedding { continuous_to_fun := h₁, continuous_inv_fun := h₂, .. e } end normed
730a56ec7e2012b8353f5aac92622f84bd4023d5
618003631150032a5676f229d13a079ac875ff77
/src/analysis/normed_space/point_reflection.lean
3f02152d54ef15b4f8ee2b4d4fd6d781c005fad0
[ "Apache-2.0" ]
permissive
awainverse/mathlib
939b68c8486df66cfda64d327ad3d9165248c777
ea76bd8f3ca0a8bf0a166a06a475b10663dec44a
refs/heads/master
1,659,592,962,036
1,590,987,592,000
1,590,987,592,000
268,436,019
1
0
Apache-2.0
1,590,990,500,000
1,590,990,500,000
null
UTF-8
Lean
false
false
3,441
lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Yury Kudryashov -/ import algebra.midpoint import topology.metric_space.isometry /-! # Point reflection in a point as an `isometric` homeomorphism Given a `normed_group E` and `x : E`, we define `isometric.point_reflection x` to be the point reflection in `x` interpreted as an `isometric` homeomorphism. Point reflection is defined as an `equiv.perm` in `data.equiv.mul_add`. In this file we restate results about `equiv.point_reflection` for an `isometric.point_reflection`, and add a few results about `dist`. ## Tags point reflection, isometric -/ variables (R : Type*) {E : Type*} lemma equiv.point_reflection_fixed_iff_of_module [ring R] [invertible (2:R)] [add_comm_group E] [module R E] {x y : E} : (equiv.point_reflection x : E → E) y = y ↔ y = x := equiv.point_reflection_fixed_iff_of_bit0_inj $ λ x y h, by rw [← one_smul R x, ← one_smul R y, ← inv_of_mul_self (2:R), mul_smul, mul_smul, two_smul, two_smul, ← bit0, ← bit0, h] namespace isometric section normed_group variables [normed_group E] /-- Point reflection in `x` as an `isometric` homeomorphism. -/ def point_reflection (x : E) : E ≃ᵢ E := (isometric.neg E).trans (isometric.add_left (x + x)) lemma point_reflection_apply (x y : E) : (point_reflection x : E → E) y = x + x - y := rfl @[simp] lemma point_reflection_to_equiv (x : E) : (point_reflection x).to_equiv = equiv.point_reflection x := rfl @[simp] lemma point_reflection_self (x : E) : (point_reflection x : E → E) x = x := add_sub_cancel _ _ lemma point_reflection_involutive (x : E) : function.involutive (point_reflection x : E → E) := equiv.point_reflection_involutive x @[simp] lemma point_reflection_symm (x : E) : (point_reflection x).symm = point_reflection x := to_equiv_inj $ equiv.point_reflection_symm x @[simp] lemma point_reflection_dist_fixed (x y : E) : dist ((point_reflection x : E → E) y) x = dist y x := by rw [← (point_reflection x).dist_eq y x, point_reflection_self] lemma point_reflection_dist_self' (x y : E) : dist ((point_reflection x : E → E) y) y = dist (x + x) (y + y) := by { simp only [point_reflection_apply, dist_eq_norm], congr' 1, abel } end normed_group section module variables [ring R] [invertible (2:R)] [normed_group E] [module R E] @[simp] lemma point_reflection_midpoint_left (x y : E) : (point_reflection (midpoint R x y) : E → E) x = y := equiv.point_reflection_midpoint_left R x y @[simp] lemma point_reflection_midpoint_right (x y : E) : (point_reflection (midpoint R x y) : E → E) y = x := equiv.point_reflection_midpoint_right R x y variable (R) include R lemma point_reflection_fixed_iff {x y : E} : (point_reflection x : E → E) y = y ↔ y = x := equiv.point_reflection_fixed_iff_of_module R end module section normed_space variables (R) [normed_field R] [normed_group E] [normed_space R E] lemma point_reflection_dist_self (x y : E) : dist ((point_reflection x : E → E) y) y = ∥(2:R)∥ * dist x y := by simp only [point_reflection_dist_self', ← two_smul R x, ← two_smul R y, dist_smul] end normed_space lemma point_reflection_dist_self_real [normed_group E] [normed_space ℝ E] (x y : E) : dist ((point_reflection x : E → E) y) y = 2 * dist x y := by simp [point_reflection_dist_self ℝ x y, real.norm_two] end isometric
587ca62dc266c44c9b4896bb36598d026fdc2711
57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d
/tests/lean/run/implicitApplyIssue.lean
aaf772b5503481afd1ac788bb74edb5230efcc82
[ "Apache-2.0" ]
permissive
collares/lean4
861a9269c4592bce49b71059e232ff0bfe4594cc
52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee
refs/heads/master
1,691,419,031,324
1,618,678,138,000
1,618,678,138,000
358,989,750
0
0
Apache-2.0
1,618,696,333,000
1,618,696,333,000
null
UTF-8
Lean
false
false
778
lean
def Set α := α → Prop class HasMem (α : outParam $ Type u) (β : Type v) where mem : α → β → Prop infix:50 " ∈ " => HasMem.mem instance : HasMem α (Set α) := ⟨λ a s => s a⟩ instance : HasLessEq (Set α) := ⟨λ s t => ∀ {x : α}, x ∈ s → x ∈ t⟩ class HasInf (P : Type u) where inf : P → P → P infix:70 " ⊓ " => HasInf.inf instance : HasInf (Set α) := ⟨λ s t x => x ∈ s ∧ x ∈ t⟩ theorem infLeLeft {s t : Set α} : s ⊓ t ≤ s := And.left theorem infLeRight {s t : Set α} : s ⊓ t ≤ t := And.right theorem inter_mem_sets_iff (f : Set (Set α)) (hf : ∀ {s t}, s ∈ f → s ≤ t → t ∈ f) : x ⊓ y ∈ f → x ∈ f ∧ y ∈ f := by intro h refine ⟨hf h infLeLeft, hf h ?_⟩ apply infLeRight
ff6507e190d997ddcc21cb037c8b9ec56c9b11a1
4727251e0cd73359b15b664c3170e5d754078599
/src/tactic/rewrite.lean
6fee7e9216cb98535e343c02f23d0a8874f3d05c
[ "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
8,072
lean
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import data.dlist import tactic.core namespace tactic open expr list meta def match_fn (fn : expr) : expr → tactic (expr × expr) | (app (app fn' e₀) e₁) := unify fn fn' $> (e₀, e₁) | _ := failed meta def fill_args : expr → tactic (expr × list expr) | (pi n bi d b) := do v ← mk_meta_var d, (r, vs) ← fill_args (b.instantiate_var v), return (r, v::vs) | e := return (e, []) meta def mk_assoc_pattern' (fn : expr) : expr → tactic (dlist expr) | e := (do (e₀, e₁) ← match_fn fn e, (++) <$> mk_assoc_pattern' e₀ <*> mk_assoc_pattern' e₁) <|> pure (dlist.singleton e) meta def mk_assoc_pattern (fn e : expr) : tactic (list expr) := dlist.to_list <$> mk_assoc_pattern' fn e meta def mk_assoc (fn : expr) : list expr → tactic expr | [] := failed | [x] := pure x | (x₀ :: x₁ :: xs) := mk_assoc (fn x₀ x₁ :: xs) meta def chain_eq_trans : list expr → tactic expr | [] := to_expr ``(rfl) | [e] := pure e | (e :: es) := chain_eq_trans es >>= mk_eq_trans e meta def unify_prefix : list expr → list expr → tactic unit | [] _ := pure () | _ [] := failed | (x :: xs) (y :: ys) := unify x y >> unify_prefix xs ys meta def match_assoc_pattern' (p : list expr) : list expr → tactic (list expr × list expr) | es := unify_prefix p es $> ([], es.drop p.length) <|> match es with | [] := failed | (x :: xs) := prod.map (cons x) id <$> match_assoc_pattern' xs end meta def match_assoc_pattern (fn p e : expr) : tactic (list expr × list expr) := do p' ← mk_assoc_pattern fn p, e' ← mk_assoc_pattern fn e, match_assoc_pattern' p' e' /-- Tag for proofs generated by `assoc_rewrite`. -/ def id_tag.assoc_proof := () meta def mk_eq_proof (fn : expr) (e₀ e₁ : list expr) (p : expr) : tactic (expr × expr × expr) := do (l, r) ← infer_type p >>= match_eq, if e₀.empty ∧ e₁.empty then pure (l, r, p) else do l' ← mk_assoc fn (e₀ ++ [l] ++ e₁), r' ← mk_assoc fn (e₀ ++ [r] ++ e₁), t ← infer_type l', v ← mk_local_def `x t, e ← mk_assoc fn (e₀ ++ [v] ++ e₁), p ← mk_congr_arg (e.lambdas [v]) p, p' ← mk_app ``eq [l', r'], let p' := mk_tagged_proof p' p ``id_tag.assoc_proof, return (l', r', p') meta def assoc_root (fn assoc : expr) : expr → tactic (expr × expr) | e := (do (e₀, e₁) ← match_fn fn e, (ea, eb) ← match_fn fn e₁, let e' := fn (fn e₀ ea) eb, p' ← mk_eq_symm (assoc e₀ ea eb), (e'', p'') ← assoc_root e', prod.mk e'' <$> mk_eq_trans p' p'') <|> prod.mk e <$> mk_eq_refl e meta def assoc_refl' (fn assoc : expr) : expr → expr → tactic expr | l r := (is_def_eq l r >> mk_eq_refl l) <|> do (l', l_p) ← assoc_root fn assoc l <|> fail "A", (el₀, el₁) ← match_fn fn l' <|> fail "B", (r', r_p) ← assoc_root fn assoc r <|> fail "C", (er₀, er₁) ← match_fn fn r' <|> fail "D", p₀ ← assoc_refl' el₀ er₀, p₁ ← is_def_eq el₁ er₁ >> mk_eq_refl el₁, f_eq ← mk_congr_arg fn p₀ <|> fail "G", p' ← mk_congr f_eq p₁ <|> fail "H", r_p' ← mk_eq_symm r_p, chain_eq_trans [l_p, p', r_p'] meta def assoc_refl (fn : expr) : tactic unit := do (l, r) ← target >>= match_eq, assoc ← mk_mapp ``is_associative.assoc [none, fn, none] <|> fail format!"{fn} is not associative", assoc_refl' fn assoc l r >>= tactic.exact meta def flatten (fn assoc e : expr) : tactic (expr × expr) := do ls ← mk_assoc_pattern fn e, e' ← mk_assoc fn ls, p ← assoc_refl' fn assoc e e', return (e', p) meta def assoc_rewrite_intl (assoc h e : expr) : tactic (expr × expr) := do t ← infer_type h, (lhs, rhs) ← match_eq t, let fn := lhs.app_fn.app_fn, (l, r) ← match_assoc_pattern fn lhs e, (lhs', rhs', h') ← mk_eq_proof fn l r h, e_p ← assoc_refl' fn assoc e lhs', (rhs'', rhs_p) ← flatten fn assoc rhs', final_p ← chain_eq_trans [e_p, h', rhs_p], return (rhs'', final_p) -- TODO(Simon): visit expressions built of `fn` nested inside other such expressions: -- e.g.: x + f (a + b + c) + y should generate two rewrite candidates meta def enum_assoc_subexpr' (fn : expr) : expr → tactic (dlist expr) | e := dlist.singleton e <$ (match_fn fn e >> guard (¬ e.has_var)) <|> expr.mfoldl (λ es e', (++ es) <$> enum_assoc_subexpr' e') dlist.empty e meta def enum_assoc_subexpr (fn e : expr) : tactic (list expr) := dlist.to_list <$> enum_assoc_subexpr' fn e meta def mk_assoc_instance (fn : expr) : tactic expr := do t ← mk_mapp ``is_associative [none, fn], inst ← prod.snd <$> solve_aux t assumption <|> (mk_instance t >>= assertv `_inst t) <|> fail format!"{fn} is not associative", mk_mapp ``is_associative.assoc [none, fn, inst] meta def assoc_rewrite (h e : expr) (opt_assoc : option expr := none) : tactic (expr × expr × list expr) := do (t, vs) ← infer_type h >>= fill_args, (lhs, rhs) ← match_eq t, let fn := lhs.app_fn.app_fn, es ← enum_assoc_subexpr fn e, assoc ← match opt_assoc with | none := mk_assoc_instance fn | (some assoc) := pure assoc end, (_, p) ← mfirst (assoc_rewrite_intl assoc $ h.mk_app vs) es, (e', p', _) ← tactic.rewrite p e, pure (e', p', vs) meta def assoc_rewrite_target (h : expr) (opt_assoc : option expr := none) : tactic unit := do tgt ← target, (tgt', p, _) ← assoc_rewrite h tgt opt_assoc, replace_target tgt' p meta def assoc_rewrite_hyp (h hyp : expr) (opt_assoc : option expr := none) : tactic expr := do tgt ← infer_type hyp, (tgt', p, _) ← assoc_rewrite h tgt opt_assoc, replace_hyp hyp tgt' p namespace interactive setup_tactic_parser private meta def assoc_rw_goal (rs : list rw_rule) : tactic unit := rs.mmap' $ λ r, do save_info r.pos, eq_lemmas ← get_rule_eqn_lemmas r, orelse' (do e ← to_expr' r.rule, assoc_rewrite_target e) (eq_lemmas.mfirst $ λ n, do e ← mk_const n, assoc_rewrite_target e) (eq_lemmas.empty) private meta def uses_hyp (e : expr) (h : expr) : bool := e.fold ff $ λ t _ r, r || (t = h) private meta def assoc_rw_hyp : list rw_rule → expr → tactic unit | [] hyp := skip | (r::rs) hyp := do save_info r.pos, eq_lemmas ← get_rule_eqn_lemmas r, orelse' (do e ← to_expr' r.rule, when (¬ uses_hyp e hyp) $ assoc_rewrite_hyp e hyp >>= assoc_rw_hyp rs) (eq_lemmas.mfirst $ λ n, do e ← mk_const n, assoc_rewrite_hyp e hyp >>= assoc_rw_hyp rs) (eq_lemmas.empty) private meta def assoc_rw_core (rs : parse rw_rules) (loca : parse location) : tactic unit := match loca with | loc.wildcard := loca.try_apply (assoc_rw_hyp rs.rules) (assoc_rw_goal rs.rules) | _ := loca.apply (assoc_rw_hyp rs.rules) (assoc_rw_goal rs.rules) end >> try reflexivity >> try (returnopt rs.end_pos >>= save_info) /-- `assoc_rewrite [h₀,← h₁] at ⊢ h₂` behaves like `rewrite [h₀,← h₁] at ⊢ h₂` with the exception that associativity is used implicitly to make rewriting possible. It works for any function `f` for which an `is_associative f` instance can be found. ``` example {α : Type*} (f : α → α → α) [is_associative α f] (a b c d x : α) : let infix `~` := f in b ~ c = x → (a ~ b ~ c ~ d) = (a ~ x ~ d) := begin intro h, assoc_rw h, end ``` -/ meta def assoc_rewrite (q : parse rw_rules) (l : parse location) : tactic unit := propagate_tags (assoc_rw_core q l) /-- synonym for `assoc_rewrite` -/ meta def assoc_rw (q : parse rw_rules) (l : parse location) : tactic unit := assoc_rewrite q l add_tactic_doc { name := "assoc_rewrite", category := doc_category.tactic, decl_names := [`tactic.interactive.assoc_rewrite, `tactic.interactive.assoc_rw], tags := ["rewriting"], inherit_description_from := `tactic.interactive.assoc_rewrite } end interactive end tactic
2141aac6e15f00ce3480e96c2356b713df445ab4
3268ab3a126f0fef71459fbf170dc38efe5d0506
/spectrum/trunc.hlean
de2efefb951e24b93b5dc34d7a0c89caafdfdd9e
[ "Apache-2.0" ]
permissive
soraismus/Spectral
f043fed1a4e02ddfeba531769b2980eb817471f4
32512bf47db3a1b932856e7ed7c7830b1fc07ef0
refs/heads/master
1,585,628,705,579
1,538,609,948,000
1,538,609,974,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
10,955
hlean
/- Copyright (c) 2017 Floris van Doorn and Ulrik Buchholtz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Ulrik Buchholtz Truncatedness and truncation of spectra -/ import .basic open int trunc eq is_trunc lift unit pointed equiv is_equiv algebra EM trunc_index namespace spectrum /- interactions of ptrunc / trunc with maxm2 -/ definition ptrunc_maxm2_change_int {k l : ℤ} (p : k = l) (X : Type*) : ptrunc (maxm2 k) X ≃* ptrunc (maxm2 l) X := ptrunc_change_index (ap maxm2 p) X definition is_trunc_maxm2_change_int {k l : ℤ} (X : pType) (p : k = l) : is_trunc (maxm2 k) X → is_trunc (maxm2 l) X := by induction p; exact id definition is_trunc_maxm2_loop {k : ℤ} {A : Type*} (H : is_trunc (maxm2 (k+1)) A) : is_trunc (maxm2 k) (Ω A) := begin induction k with k k, apply is_trunc_loop, exact H, apply is_contr_loop, cases k with k, { exact H }, { apply is_trunc_succ, apply is_trunc_succ, exact H } end definition loop_ptrunc_maxm2_pequiv {k : ℤ} {l : ℕ₋₂} (p : maxm2 (k+1) = l) (X : Type*) : Ω (ptrunc l X) ≃* ptrunc (maxm2 k) (Ω X) := begin induction p, induction k with k k, { exact loop_ptrunc_pequiv k X }, { refine pequiv_of_is_contr _ _ _ !is_trunc_trunc, apply is_contr_loop, cases k with k, { change is_set (trunc 0 X), apply _ }, { change is_set (trunc -2 X), apply _ }} end definition loop_ptrunc_maxm2_pequiv_ptrunc_elim' {k : ℤ} {l : ℕ₋₂} (p : maxm2 (k+1) = l) {A B : Type*} (f : A →* B) {H : is_trunc l B} : Ω→ (ptrunc.elim l f) ∘* (loop_ptrunc_maxm2_pequiv p A)⁻¹ᵉ* ~* @ptrunc.elim (maxm2 k) _ _ (is_trunc_maxm2_loop (is_trunc_of_eq p⁻¹ H)) (Ω→ f) := begin induction p, induction k with k k, { refine pwhisker_right _ (ap1_phomotopy _) ⬝* @(ap1_ptrunc_elim k f) H, apply ptrunc_elim_phomotopy2, reflexivity }, { apply phomotopy_of_is_contr_cod_pmap, exact is_trunc_maxm2_loop H } end definition loop_ptrunc_maxm2_pequiv_ptrunc_elim {k : ℤ} {l : ℕ₋₂} (p : maxm2 (k+1) = l) {A B : Type*} (f : A →* B) {H1 : is_trunc ((maxm2 k).+1) B } {H2 : is_trunc l B} : Ω→ (ptrunc.elim l f) ∘* (loop_ptrunc_maxm2_pequiv p A)⁻¹ᵉ* ~* ptrunc.elim (maxm2 k) (Ω→ f) := begin induction p, induction k with k k: esimp at H1, { refine pwhisker_right _ (ap1_phomotopy _) ⬝* ap1_ptrunc_elim k f, apply ptrunc_elim_phomotopy2, reflexivity }, { apply phomotopy_of_is_contr_cod } end definition loop_ptrunc_maxm2_pequiv_ptr {k : ℤ} {l : ℕ₋₂} (p : maxm2 (k+1) = l) (A : Type*) : Ω→ (ptr l A) ~* (loop_ptrunc_maxm2_pequiv p A)⁻¹ᵉ* ∘* ptr (maxm2 k) (Ω A) := begin induction p, induction k with k k, { exact ap1_ptr k A }, { apply phomotopy_pinv_left_of_phomotopy, apply phomotopy_of_is_contr_cod_pmap, apply is_trunc_trunc } end definition is_trunc_of_is_trunc_maxm2 (k : ℤ) (X : Type) : is_trunc (maxm2 k) X → is_trunc (max0 k) X := λ H, @is_trunc_of_le X _ _ (maxm2_le_maxm0 k) H definition ptrunc_maxm2_pred {n m : ℤ} (A : Type*) (p : n - 1 = m) : ptrunc (maxm2 m) A ≃* ptrunc (trunc_index.pred (maxm2 n)) A := begin cases n with n, cases n with n, apply pequiv_of_is_contr, induction p, apply is_trunc_trunc, apply is_contr_ptrunc_minus_one, exact ptrunc_change_index (ap maxm2 (p⁻¹ ⬝ !add_sub_cancel)) A, exact ptrunc_change_index (ap maxm2 p⁻¹) A end definition ptrunc_maxm2_pred_nat {n : ℕ} {m l : ℤ} (A : Type*) (p : nat.succ n = l) (q : pred l = m) (r : maxm2 m = trunc_index.pred (maxm2 (nat.succ n))) : @ptrunc_maxm2_pred (nat.succ n) m A (ap pred p ⬝ q) ~* ptrunc_change_index r A := begin have ap maxm2 ((ap pred p ⬝ q)⁻¹ ⬝ add_sub_cancel n 1) = r, from !is_set.elim, induction this, reflexivity end /- truncatedness of spectra -/ definition is_strunc [reducible] (k : ℤ) (E : spectrum) : Type := Π (n : ℤ), is_trunc (maxm2 (k + n)) (E n) definition is_strunc_change_int {k l : ℤ} (E : spectrum) (p : k = l) : is_strunc k E → is_strunc l E := begin induction p, exact id end definition is_strunc_of_le {k l : ℤ} (E : spectrum) (H : k ≤ l) : is_strunc k E → is_strunc l E := begin intro T, intro n, exact is_trunc_of_le (E n) (maxm2_monotone (algebra.add_le_add_right H n)) _ end definition is_strunc_pequiv_closed {k : ℤ} {E F : spectrum} (H : Πn, E n ≃* F n) (H2 : is_strunc k E) : is_strunc k F := λn, is_trunc_equiv_closed (maxm2 (k + n)) (H n) _ definition is_strunc_sunit (n : ℤ) : is_strunc n sunit := begin intro k, apply is_trunc_lift, apply is_trunc_unit end open option definition is_strunc_add_point_spectrum {X : Type} {Y : X → spectrum} {s₀ : ℤ} (H : Πx, is_strunc s₀ (Y x)) : Π(x : X₊), is_strunc s₀ (add_point_spectrum Y x) | (some x) := proof H x qed | none := begin intro k, apply is_trunc_lift, apply is_trunc_unit end definition is_strunc_EM_spectrum (G : AbGroup) : is_strunc 0 (EM_spectrum G) := begin intro n, induction n with n n, { -- case ≥ 0 apply is_trunc_maxm2_change_int (EM G n) (zero_add n)⁻¹, apply is_trunc_EM }, { change is_contr (EM_spectrum G (-[1+n])), induction n with n IH, { -- case = -1 apply is_contr_loop, exact is_trunc_EM G 0 }, { -- case < -1 apply is_trunc_loop, apply is_trunc_succ, exact IH }} end definition trivial_shomotopy_group_of_is_strunc (E : spectrum) {n k : ℤ} (K : is_strunc n E) (H : n < k) : is_contr (πₛ[k] E) := let m := n + (2 - k) in have I : m < 2, from calc m = (2 - k) + n : int.add_comm n (2 - k) ... < (2 - k) + k : add_lt_add_left H (2 - k) ... = 2 : sub_add_cancel 2 k, @trivial_homotopy_group_of_is_trunc (E (2 - k)) (max0 m) 2 (is_trunc_of_is_trunc_maxm2 m (E (2 - k)) (K (2 - k))) (nat.succ_le_succ (max0_le_of_le (le_sub_one_of_lt I))) /- truncation of spectra -/ definition strunc [constructor] (k : ℤ) (E : spectrum) : spectrum := spectrum.MK (λ(n : ℤ), ptrunc (maxm2 (k + n)) (E n)) (λ(n : ℤ), ptrunc_pequiv_ptrunc (maxm2 (k + n)) (equiv_glue E n) ⬝e* (loop_ptrunc_maxm2_pequiv (ap maxm2 (add.assoc k n 1)) (E (n+1)))⁻¹ᵉ*) definition strunc_change_int [constructor] {k l : ℤ} (E : spectrum) (p : k = l) : strunc k E →ₛ strunc l E := begin induction p, reflexivity end definition is_strunc_strunc (k : ℤ) (E : spectrum) : is_strunc k (strunc k E) := λ n, is_trunc_trunc (maxm2 (k + n)) (E n) definition is_strunc_strunc_pred (X : spectrum) (k : ℤ) : is_strunc k (strunc (k - 1) X) := λn, @(is_trunc_of_le _ (maxm2_monotone (add_le_add_right (sub_one_le k) n))) !is_strunc_strunc definition is_strunc_strunc_of_is_strunc (k : ℤ) {l : ℤ} {E : spectrum} (H : is_strunc l E) : is_strunc l (strunc k E) := λ n, !is_trunc_trunc_of_is_trunc definition str [constructor] (k : ℤ) (E : spectrum) : E →ₛ strunc k E := smap.mk (λ n, ptr (maxm2 (k + n)) (E n)) abstract begin intro n, apply psquare_of_phomotopy, refine !passoc ⬝* pwhisker_left _ !ptr_natural ⬝* _, refine !passoc⁻¹* ⬝* pwhisker_right _ !loop_ptrunc_maxm2_pequiv_ptr⁻¹*, end end definition strunc_elim [constructor] {k : ℤ} {E F : spectrum} (f : E →ₛ F) (H : is_strunc k F) : strunc k E →ₛ F := smap.mk (λn, ptrunc.elim (maxm2 (k + n)) (f n)) abstract begin intro n, apply psquare_of_phomotopy, symmetry, refine !passoc⁻¹* ⬝* pwhisker_right _ !loop_ptrunc_maxm2_pequiv_ptrunc_elim' ⬝* _, refine @(ptrunc_elim_ptrunc_functor _ _ _) _ ⬝* _, refine _ ⬝* @(ptrunc_elim_pcompose _ _ _) _ _, apply is_trunc_maxm2_loop, refine is_trunc_of_eq _ (H (n+1)), exact ap maxm2 (add.assoc k n 1)⁻¹, apply ptrunc_elim_phomotopy2, apply phomotopy_of_psquare, apply ptranspose, apply smap.glue_square end end definition strunc_functor [constructor] (k : ℤ) {E F : spectrum} (f : E →ₛ F) : strunc k E →ₛ strunc k F := strunc_elim (str k F ∘ₛ f) (is_strunc_strunc k F) /- truncated spectra -/ structure truncspectrum (n : ℤ) := (carrier : spectrum) (struct : is_strunc n carrier) notation n `-spectrum` := truncspectrum n attribute truncspectrum.carrier [coercion] definition genspectrum_of_truncspectrum [coercion] (n : ℤ) : n-spectrum → gen_spectrum +ℤ := λ E, truncspectrum.carrier E /- Comment (by Floris): I think we should really not bundle truncated spectra up, unless we are interested in the type of truncated spectra (e.g. when proving n-spectrum ≃ ...). Properties of truncated a spectrum should just be stated with two assumptions (X : spectrum) (H : is_strunc n X) -/ /- truncatedness of spi and sp_cotensor assuming the domain has a level of connectedness -/ section open is_conn definition is_conn_maxm1_of_maxm2 (A : Type*) (n : ℤ) : is_conn (maxm2 n) A → is_conn (maxm1m1 n).+1 A := begin intro H, induction n with n n, { exact H }, { exact is_conn_minus_one A (tr pt) } end definition is_trunc_maxm2_of_maxm1 (A : Type*) (n : ℤ) : is_trunc (maxm1m1 n).+1 A → is_trunc (maxm2 n) A := begin intro H, induction n with n n, { exact H}, { apply is_contr_of_merely_prop, { exact H }, { exact tr pt } } end variables (A : Type*) (n : ℤ) [H : is_conn (maxm2 n) A] include H definition is_trunc_maxm2_ppi (k l : ℤ) (H3 : l ≤ n+1+k) (P : A → Type*) (H2 : Πa, is_trunc (maxm2 l) (P a)) : is_trunc (maxm2 k) (Π*(a : A), P a) := is_trunc_maxm2_of_maxm1 (Π*(a : A), P a) k (@is_trunc_ppi_of_is_conn A (maxm1m1 n) (is_conn_maxm1_of_maxm2 A n H) (maxm1m1 k) _ (le.trans (maxm2_monotone H3) (maxm2_le n k)) P H2) definition is_strunc_spi_of_is_conn (k l : ℤ) (H3 : l ≤ n+1+k) (P : A → spectrum) (H2 : Πa, is_strunc l (P a)) : is_strunc k (spi A P) := begin intro m, unfold spi, exact is_trunc_maxm2_ppi A n (k+m) _ (le.trans (add_le_add_right H3 _) (le_of_eq (add.assoc (n+1) k m))) (λ a, P a m) (λa, H2 a m) end end definition is_strunc_spi_of_le {A : Type*} (k n : ℤ) (H : n ≤ k) (P : A → spectrum) (H2 : Πa, is_strunc n (P a)) : is_strunc k (spi A P) := begin assert K : n ≤ -[1+ 0] + 1 + k, { krewrite (int.zero_add k), exact H }, { exact @is_strunc_spi_of_is_conn A (-[1+ 0]) (is_conn.is_conn_minus_two A) k _ K P H2 } end definition is_strunc_spi {A : Type*} (n : ℤ) (P : A → spectrum) (H : Πa, is_strunc n (P a)) : is_strunc n (spi A P) := is_strunc_spi_of_le n n !le.refl P H definition is_strunc_sp_cotensor (n : ℤ) (A : Type*) {Y : spectrum} (H : is_strunc n Y) : is_strunc n (sp_cotensor A Y) := is_strunc_pequiv_closed (λn, !pppi_pequiv_ppmap) (is_strunc_spi n (λa, Y) (λa, H)) definition is_strunc_sp_ucotensor (n : ℤ) (A : Type) {Y : spectrum} (H : is_strunc n Y) : is_strunc n (sp_ucotensor A Y) := λk, !pi.is_trunc_arrow end spectrum
1f6008d189de3e6ebe8c35b83a79f7323d136b9b
1abd1ed12aa68b375cdef28959f39531c6e95b84
/src/analysis/special_functions/complex/arg.lean
d8ed035eb2dbb6a28bd18642d2636af1e9cbbdff
[ "Apache-2.0" ]
permissive
jumpy4/mathlib
d3829e75173012833e9f15ac16e481e17596de0f
af36f1a35f279f0e5b3c2a77647c6bf2cfd51a13
refs/heads/master
1,693,508,842,818
1,636,203,271,000
1,636,203,271,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
12,528
lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson -/ import analysis.special_functions.trigonometric.inverse /-! # The argument of a complex number. We define `arg : ℂ → ℝ`, returing a real number in the range (-π, π], such that for `x ≠ 0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`, while `arg 0` defaults to `0` -/ noncomputable theory namespace complex open_locale real topological_space open filter /-- `arg` returns values in the range (-π, π], such that for `x ≠ 0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`, `arg 0` defaults to `0` -/ noncomputable def arg (x : ℂ) : ℝ := if 0 ≤ x.re then real.arcsin (x.im / x.abs) else if 0 ≤ x.im then real.arcsin ((-x).im / x.abs) + π else real.arcsin ((-x).im / x.abs) - π lemma arg_le_pi (x : ℂ) : arg x ≤ π := if hx₁ : 0 ≤ x.re then by rw [arg, if_pos hx₁]; exact le_trans (real.arcsin_le_pi_div_two _) (le_of_lt (half_lt_self real.pi_pos)) else if hx₂ : 0 ≤ x.im then by rw [arg, if_neg hx₁, if_pos hx₂, ← le_sub_iff_add_le, sub_self, real.arcsin_nonpos, neg_im, neg_div, neg_nonpos]; exact div_nonneg hx₂ (abs_nonneg _) else by rw [arg, if_neg hx₁, if_neg hx₂]; exact sub_le_iff_le_add.2 (le_trans (real.arcsin_le_pi_div_two _) (by linarith [real.pi_pos])) lemma neg_pi_lt_arg (x : ℂ) : -π < arg x := if hx₁ : 0 ≤ x.re then by rw [arg, if_pos hx₁]; exact lt_of_lt_of_le (neg_lt_neg (half_lt_self real.pi_pos)) (real.neg_pi_div_two_le_arcsin _) else have hx : x ≠ 0, from λ h, by simpa [h, lt_irrefl] using hx₁, if hx₂ : 0 ≤ x.im then by { rw [arg, if_neg hx₁, if_pos hx₂, ← sub_lt_iff_lt_add'], refine lt_of_lt_of_le _ real.pi_pos.le, rw [neg_im, sub_lt_iff_lt_add', add_zero, neg_lt, neg_div, real.arcsin_neg, neg_neg], exact (real.arcsin_le_pi_div_two _).trans_lt (half_lt_self real.pi_pos) } else by rw [arg, if_neg hx₁, if_neg hx₂, lt_sub_iff_add_lt, neg_add_self, real.arcsin_pos, neg_im]; exact div_pos (neg_pos.2 (lt_of_not_ge hx₂)) (abs_pos.2 hx) lemma arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg {x : ℂ} (hxr : x.re < 0) (hxi : 0 ≤ x.im) : arg x = arg (-x) + π := have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos], by rw [arg, arg, if_neg (not_le.2 hxr), if_pos this, if_pos hxi, abs_neg] lemma arg_eq_arg_neg_sub_pi_of_im_neg_of_re_neg {x : ℂ} (hxr : x.re < 0) (hxi : x.im < 0) : arg x = arg (-x) - π := have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos], by rw [arg, arg, if_neg (not_le.2 hxr), if_neg (not_le.2 hxi), if_pos this, abs_neg] @[simp] lemma arg_zero : arg 0 = 0 := by simp [arg, le_refl] @[simp] lemma arg_one : arg 1 = 0 := by simp [arg, zero_le_one] @[simp] lemma arg_neg_one : arg (-1) = π := by simp [arg, le_refl, not_le.2 (@zero_lt_one ℝ _ _)] @[simp] lemma arg_I : arg I = π / 2 := by simp [arg, le_refl] @[simp] lemma arg_neg_I : arg (-I) = -(π / 2) := by simp [arg, le_refl] lemma sin_arg (x : ℂ) : real.sin (arg x) = x.im / x.abs := by unfold arg; split_ifs; simp [sub_eq_add_neg, arg, real.sin_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1 (abs_le.1 (abs_im_div_abs_le_one x)).2, real.sin_add, neg_div, real.arcsin_neg, real.sin_neg] private lemma cos_arg_of_re_nonneg {x : ℂ} (hx : x ≠ 0) (hxr : 0 ≤ x.re) : real.cos (arg x) = x.re / x.abs := have 0 ≤ 1 - (x.im / abs x) ^ 2, from sub_nonneg.2 $ by rw [sq, ← _root_.abs_mul_self, _root_.abs_mul, ← sq]; exact pow_le_one _ (_root_.abs_nonneg _) (abs_im_div_abs_le_one _), by rw [eq_div_iff_mul_eq (mt abs_eq_zero.1 hx), ← real.mul_self_sqrt (abs_nonneg x), arg, if_pos hxr, real.cos_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1 (abs_le.1 (abs_im_div_abs_le_one x)).2, ← real.sqrt_mul (abs_nonneg _), ← real.sqrt_mul this, sub_mul, div_pow, ← sq, div_mul_cancel _ (pow_ne_zero 2 (mt abs_eq_zero.1 hx)), one_mul, sq, mul_self_abs, norm_sq_apply, sq, add_sub_cancel, real.sqrt_mul_self hxr] lemma cos_arg {x : ℂ} (hx : x ≠ 0) : real.cos (arg x) = x.re / x.abs := if hxr : 0 ≤ x.re then cos_arg_of_re_nonneg hx hxr else have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos] using hxr, if hxi : 0 ≤ x.im then have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos] using hxr, by rw [arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg (not_le.1 hxr) hxi, real.cos_add_pi, cos_arg_of_re_nonneg (neg_ne_zero.2 hx) this]; simp [neg_div] else by rw [arg_eq_arg_neg_sub_pi_of_im_neg_of_re_neg (not_le.1 hxr) (not_le.1 hxi)]; simp [sub_eq_add_neg, real.cos_add, neg_div, cos_arg_of_re_nonneg (neg_ne_zero.2 hx) this] lemma tan_arg {x : ℂ} : real.tan (arg x) = x.im / x.re := begin by_cases h : x = 0, { simp only [h, zero_div, complex.zero_im, complex.arg_zero, real.tan_zero, complex.zero_re] }, rw [real.tan_eq_sin_div_cos, sin_arg, cos_arg h, div_div_div_cancel_right _ (mt abs_eq_zero.1 h)] end lemma arg_cos_add_sin_mul_I {x : ℝ} (hx₁ : -π < x) (hx₂ : x ≤ π) : arg (cos x + sin x * I) = x := if hx₃ : -(π / 2) ≤ x ∧ x ≤ π / 2 then have hx₄ : 0 ≤ (cos x + sin x * I).re, by simp; exact real.cos_nonneg_of_mem_Icc hx₃, by rw [arg, if_pos hx₄]; simp [abs_cos_add_sin_mul_I, sin_of_real_re, real.arcsin_sin hx₃.1 hx₃.2] else if hx₄ : x < -(π / 2) then have hx₅ : ¬0 ≤ (cos x + sin x * I).re := suffices ¬ 0 ≤ real.cos x, by simpa, not_le.2 $ by rw ← real.cos_neg; apply real.cos_neg_of_pi_div_two_lt_of_lt; linarith, have hx₆ : ¬0 ≤ (cos ↑x + sin ↑x * I).im := suffices real.sin x < 0, by simpa, by apply real.sin_neg_of_neg_of_neg_pi_lt; linarith, suffices -π + -real.arcsin (real.sin x) = x, by rw [arg, if_neg hx₅, if_neg hx₆]; simpa [sub_eq_add_neg, add_comm, abs_cos_add_sin_mul_I, sin_of_real_re], by rw [← real.arcsin_neg, ← real.sin_add_pi, real.arcsin_sin]; try {simp [add_left_comm]}; linarith else have hx₅ : π / 2 < x, by cases not_and_distrib.1 hx₃; linarith, have hx₆ : ¬0 ≤ (cos x + sin x * I).re := suffices ¬0 ≤ real.cos x, by simpa, not_le.2 $ by apply real.cos_neg_of_pi_div_two_lt_of_lt; linarith, have hx₇ : 0 ≤ (cos x + sin x * I).im := suffices 0 ≤ real.sin x, by simpa, by apply real.sin_nonneg_of_nonneg_of_le_pi; linarith, suffices π - real.arcsin (real.sin x) = x, by rw [arg, if_neg hx₆, if_pos hx₇]; simpa [sub_eq_add_neg, add_comm, abs_cos_add_sin_mul_I, sin_of_real_re], by rw [← real.sin_pi_sub, real.arcsin_sin]; simp [sub_eq_add_neg]; linarith lemma arg_eq_arg_iff {x y : ℂ} (hx : x ≠ 0) (hy : y ≠ 0) : arg x = arg y ↔ (abs y / abs x : ℂ) * x = y := have hax : abs x ≠ 0, from (mt abs_eq_zero.1 hx), have hay : abs y ≠ 0, from (mt abs_eq_zero.1 hy), ⟨λ h, begin have hcos := congr_arg real.cos h, rw [cos_arg hx, cos_arg hy, div_eq_div_iff hax hay] at hcos, have hsin := congr_arg real.sin h, rw [sin_arg, sin_arg, div_eq_div_iff hax hay] at hsin, apply complex.ext, { rw [mul_re, ← of_real_div, of_real_re, of_real_im, zero_mul, sub_zero, mul_comm, ← mul_div_assoc, hcos, mul_div_cancel _ hax] }, { rw [mul_im, ← of_real_div, of_real_re, of_real_im, zero_mul, add_zero, mul_comm, ← mul_div_assoc, hsin, mul_div_cancel _ hax] } end, λ h, have hre : abs (y / x) * x.re = y.re, by rw ← of_real_div at h; simpa [-of_real_div, -is_R_or_C.of_real_div] using congr_arg re h, have hre' : abs (x / y) * y.re = x.re, by rw [← hre, abs_div, abs_div, ← mul_assoc, div_mul_div, mul_comm (abs _), div_self (mul_ne_zero hay hax), one_mul], have him : abs (y / x) * x.im = y.im, by rw ← of_real_div at h; simpa [-of_real_div, -is_R_or_C.of_real_div] using congr_arg im h, have him' : abs (x / y) * y.im = x.im, by rw [← him, abs_div, abs_div, ← mul_assoc, div_mul_div, mul_comm (abs _), div_self (mul_ne_zero hay hax), one_mul], have hxya : x.im / abs x = y.im / abs y, by rw [← him, abs_div, mul_comm, ← mul_div_comm, mul_div_cancel_left _ hay], have hnxya : (-x).im / abs x = (-y).im / abs y, by rw [neg_im, neg_im, neg_div, neg_div, hxya], if hxr : 0 ≤ x.re then have hyr : 0 ≤ y.re, from hre ▸ mul_nonneg (abs_nonneg _) hxr, by simp [arg, *] at * else have hyr : ¬ 0 ≤ y.re, from λ hyr, hxr $ hre' ▸ mul_nonneg (abs_nonneg _) hyr, if hxi : 0 ≤ x.im then have hyi : 0 ≤ y.im, from him ▸ mul_nonneg (abs_nonneg _) hxi, by simp [arg, *] at * else have hyi : ¬ 0 ≤ y.im, from λ hyi, hxi $ him' ▸ mul_nonneg (abs_nonneg _) hyi, by simp [arg, *] at *⟩ lemma arg_real_mul (x : ℂ) {r : ℝ} (hr : 0 < r) : arg (r * x) = arg x := if hx : x = 0 then by simp [hx] else (arg_eq_arg_iff (mul_ne_zero (of_real_ne_zero.2 (ne_of_lt hr).symm) hx) hx).2 $ by rw [abs_mul, abs_of_nonneg (le_of_lt hr), ← mul_assoc, of_real_mul, mul_comm (r : ℂ), ← div_div_eq_div_mul, div_mul_cancel _ (of_real_ne_zero.2 (ne_of_lt hr).symm), div_self (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), one_mul] lemma ext_abs_arg {x y : ℂ} (h₁ : x.abs = y.abs) (h₂ : x.arg = y.arg) : x = y := if hy : y = 0 then by simp * at * else have hx : x ≠ 0, from λ hx, by simp [*, eq_comm] at *, by rwa [arg_eq_arg_iff hx hy, h₁, div_self (of_real_ne_zero.2 (mt abs_eq_zero.1 hy)), one_mul] at h₂ lemma arg_of_real_of_nonneg {x : ℝ} (hx : 0 ≤ x) : arg x = 0 := by simp [arg, hx] lemma arg_eq_pi_iff {z : ℂ} : arg z = π ↔ z.re < 0 ∧ z.im = 0 := begin by_cases h₀ : z = 0, { simp [h₀, lt_irrefl, real.pi_ne_zero.symm] }, have h₀' : (abs z : ℂ) ≠ 0, by simpa, rw [← arg_neg_one, arg_eq_arg_iff h₀ (neg_ne_zero.2 one_ne_zero), abs_neg, abs_one, of_real_one, one_div, ← div_eq_inv_mul, div_eq_iff_mul_eq h₀', neg_one_mul, ext_iff, neg_im, of_real_im, neg_zero, @eq_comm _ z.im, and.congr_left_iff], rcases z with ⟨x, y⟩, simp only, rintro rfl, simp only [← of_real_def, of_real_eq_zero] at *, simp [← ne.le_iff_lt h₀, @neg_eq_iff_neg_eq _ _ _ x, @eq_comm _ (-x)] end lemma arg_of_real_of_neg {x : ℝ} (hx : x < 0) : arg x = π := arg_eq_pi_iff.2 ⟨hx, rfl⟩ lemma tendsto_arg_nhds_within_im_neg_of_re_neg_of_im_zero {z : ℂ} (hre : z.re < 0) (him : z.im = 0) : tendsto arg (𝓝[{z : ℂ | z.im < 0}] z) (𝓝 (-π)) := begin suffices H : tendsto (λ x : ℂ, real.arcsin ((-x).im / x.abs) - π) (𝓝[{z : ℂ | z.im < 0}] z) (𝓝 (-π)), { refine H.congr' _, have : ∀ᶠ x : ℂ in 𝓝 z, x.re < 0, from continuous_re.tendsto z (gt_mem_nhds hre), filter_upwards [self_mem_nhds_within, mem_nhds_within_of_mem_nhds this], intros w him hre, rw [arg, if_neg hre.not_le, if_neg him.not_le] }, convert (real.continuous_at_arcsin.comp_continuous_within_at ((continuous_im.continuous_at.comp_continuous_within_at continuous_within_at_neg).div continuous_abs.continuous_within_at _)).sub tendsto_const_nhds, { simp [him] }, { lift z to ℝ using him, simpa using hre.ne } end lemma continuous_within_at_arg_of_re_neg_of_im_zero {z : ℂ} (hre : z.re < 0) (him : z.im = 0) : continuous_within_at arg {z : ℂ | 0 ≤ z.im} z := begin have : arg =ᶠ[𝓝[{z : ℂ | 0 ≤ z.im}] z] λ x, real.arcsin ((-x).im / x.abs) + π, { have : ∀ᶠ x : ℂ in 𝓝 z, x.re < 0, from continuous_re.tendsto z (gt_mem_nhds hre), filter_upwards [self_mem_nhds_within, mem_nhds_within_of_mem_nhds this], intros w him hre, rw [arg, if_neg hre.not_le, if_pos him] }, refine continuous_within_at.congr_of_eventually_eq _ this _, { refine (real.continuous_at_arcsin.comp_continuous_within_at ((continuous_im.continuous_at.comp_continuous_within_at continuous_within_at_neg).div continuous_abs.continuous_within_at _)).add tendsto_const_nhds, lift z to ℝ using him, simpa using hre.ne }, { rw [arg, if_neg hre.not_le, if_pos him.ge] } end lemma tendsto_arg_nhds_within_im_nonneg_of_re_neg_of_im_zero {z : ℂ} (hre : z.re < 0) (him : z.im = 0) : tendsto arg (𝓝[{z : ℂ | 0 ≤ z.im}] z) (𝓝 π) := by simpa only [arg_eq_pi_iff.2 ⟨hre, him⟩] using (continuous_within_at_arg_of_re_neg_of_im_zero hre him).tendsto end complex
68b387c66aa4ac549d7b3d4827c67e4c438b5c5e
56762daf61566a2baf390b5d77988c29c75187e3
/src/preamble_results.lean
78a52280280c3520530e2cded972da8313188971
[]
no_license
Nicknamen/lie_group
de173ce5f1ffccb945ba05dca23ff27daef0e3b4
e0d5c4f859654e3dea092702f1320c3c72a49983
refs/heads/master
1,674,937,428,196
1,607,213,423,000
1,607,213,423,000
275,196,635
0
0
null
null
null
null
UTF-8
Lean
false
false
6,904
lean
/- Copyright © 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Nicolò Cavalleri. -/ /- THIS FILE CONTAINS SCATTERED RESULTS TO BE CORRECTLY PLACED IN MATHLIB -/ import .times_cont_mdiff import tactic import topology.algebra.module import topology.algebra.continuous_functions noncomputable theory section prod /- To be placed into topology/contructions -/ universes u v w x variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x} variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ] @[inline, reducible] def map_diag (A : Type*) : (A → A×A) := (λ a : A, (a, a)) lemma continuous.map_diag : continuous (map_diag α) := continuous_id.prod_mk continuous_id end prod section /- To be placed into topology/local_homemorph -/ namespace local_homeomorph variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {η : Type*} {ε : Type*} [topological_space α] [topological_space β] [topological_space γ] [topological_space δ] [topological_space η] [topological_space ε] (e : local_homeomorph α β) (f : local_homeomorph β γ) (e' : local_homeomorph δ η) (f' : local_homeomorph η ε) end local_homeomorph end section preamble_results section times_cont_diff /- To be placed into analysis/calculus/times_cont_diff -/ 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] {T : Type*} [normed_group T] [normed_space 𝕜 T] end times_cont_diff section /- To be placed into geometry/manifold/manifold -/ variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜] {E : Type*} [normed_group E] [normed_space 𝕜 E] {E' : Type*} [normed_group E'] [normed_space 𝕜 E'] {H : Type*} [topological_space H] {H' : Type*} [topological_space H'] section smooth /- Not really sure where this should go. Either on geometry/manifold/times_cont_mdiff or on a new file. -/ /-- Smooth means C^∞. I truly believe this definition should exists as writing `times_cont_mdiff I I' ⊤ f` makes everything unreadable and harder to understand for someone who does not know Mathlib well. -/ def smooth (I : model_with_corners 𝕜 E H) (I' : model_with_corners 𝕜 E' H') {M : Type*} [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] {N : Type*} [topological_space N] [charted_space H' N] [smooth_manifold_with_corners I' N] (f: M → N) := times_cont_mdiff I I' ⊤ f def smooth_on (I : model_with_corners 𝕜 E H) (I' : model_with_corners 𝕜 E' H') {M : Type*} [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] {N : Type*} [topological_space N] [charted_space H' N] [smooth_manifold_with_corners I' N] (f: M → N) (s : set M) := times_cont_mdiff_on I I' ⊤ f s def smooth_in_charts (I : model_with_corners 𝕜 E H) (I' : model_with_corners 𝕜 E' H') {M : Type*} [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] {N : Type*} [topological_space N] [charted_space H' N] [smooth_manifold_with_corners I' N] (f: M → N) := times_cont_mdiff_in_charts I I' ⊤ f def smooth_in_charts_on (I : model_with_corners 𝕜 E H) (I' : model_with_corners 𝕜 E' H') {M : Type*} [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] {N : Type*} [topological_space N] [charted_space H' N] [smooth_manifold_with_corners I' N] (f: M → N) (s : set M) := times_cont_mdiff_in_charts_on I I' ⊤ f s variables {I : model_with_corners 𝕜 E H} {I' : model_with_corners 𝕜 E' H'} {M : Type*} [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] {N : Type*} [topological_space N] [charted_space H' N] [smooth_manifold_with_corners I' N] lemma smooth_in_charts_id : smooth_in_charts I I (id : M → M) := begin intros x y, rw [function.comp.left_id, set.preimage_id], unfold ext_chart_at, simp only [model_with_corners.to_local_equiv_coe_symm, local_homeomorph.coe_coe_symm, local_homeomorph.coe_coe, local_equiv.coe_trans, local_equiv.coe_trans_symm, model_with_corners.to_local_equiv_coe], have h1 := (has_groupoid.compatible (times_cont_diff_groupoid ⊤ I) (chart_mem_atlas H x) (chart_mem_atlas H y)).1, simp only [local_homeomorph.trans_to_local_equiv, local_homeomorph.coe_trans, local_homeomorph.symm_to_local_equiv] at h1, convert h1 using 1, unfold function.comp, ext1 z, rw set.mem_inter_eq, fsplit; simp only [local_equiv.trans_source, local_equiv.trans_target, and_imp, model_with_corners.to_local_equiv_coe_symm, set.mem_preimage, set.mem_range, local_homeomorph.coe_coe_symm, set.mem_inter_eq, local_equiv.symm_source, set.preimage_univ, model_with_corners.target, model_with_corners.source_eq, exists_imp_distrib, set.inter_univ], { intros w hw h2 h3, exact ⟨⟨h2, h3⟩, ⟨w, hw⟩⟩, }, { intros h2 h3 w hw, use w, exacts [hw, h2, h3], } end lemma smooth_in_charts_const {n : N} : smooth_in_charts I I' (λ x : M, n) := begin intros x y, unfold function.comp, exact times_cont_diff_on_const, end lemma tangent_bundle_proj_smooth : smooth_in_charts I.tangent I (tangent_bundle.proj I M) := begin intros x y, simp only [function.comp] with mfld_simps, sorry, end end smooth section composition variables {E'' : Type*} [normed_group E''] [normed_space 𝕜 E''] {H'' : Type*} [topological_space H''] {I'' : model_with_corners 𝕜 E'' H''} {I : model_with_corners 𝕜 E H} {I' : model_with_corners 𝕜 E' H'} {M : Type*} [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] {M' : Type*} [topological_space M'] [charted_space H' M'] [smooth_manifold_with_corners I' M'] {M'' : Type*} [topological_space M''] [charted_space H'' M''] [smooth_manifold_with_corners I'' M''] lemma smooth_on.comp {s : set M} {t : set M'} {f : M → M'} {g : M' → M''} (hg : smooth_on I' I'' g t) (hf : smooth_on I I' f s) (st : s ⊆ f ⁻¹' t) : smooth_on I I'' (g ∘ f) s := times_cont_mdiff_on.comp hg hf st lemma times_cont_mdiff.comp {n : with_top ℕ} {f : M → M'} {g : M' → M''} (hg : times_cont_mdiff I' I'' n g) (hf : times_cont_mdiff I I' n f) : times_cont_mdiff I I'' n (g ∘ f) := begin have hs : (set.univ ⊆ f ⁻¹' set.univ), by rw set.preimage_univ, have h := (times_cont_mdiff_on_univ.2 hg).comp (times_cont_mdiff_on_univ.2 hf) hs, exact times_cont_mdiff_on_univ.1 h, end lemma smooth.comp {f : M → M'} {g : M' → M''} (hg : smooth I' I'' g) (hf : smooth I I' f) : smooth I I'' (g ∘ f) := times_cont_mdiff.comp hg hf lemma smooth_in_charts.comp {f : M → M'} {g : M' → M''} (hg : smooth_in_charts I' I'' g) (hf : smooth_in_charts I I' f) : smooth_in_charts I I'' (g ∘ f) := sorry end composition end end preamble_results
26fc3bcef524f709bf5110fe1a337418d6e5d593
57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d
/src/Lean/Compiler/IR/RC.lean
4130cf2c730b18c2348e14ec7df5365ff579d031
[ "Apache-2.0" ]
permissive
collares/lean4
861a9269c4592bce49b71059e232ff0bfe4594cc
52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee
refs/heads/master
1,691,419,031,324
1,618,678,138,000
1,618,678,138,000
358,989,750
0
0
Apache-2.0
1,618,696,333,000
1,618,696,333,000
null
UTF-8
Lean
false
false
12,786
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.Runtime import Lean.Compiler.IR.CompilerM import Lean.Compiler.IR.LiveVars namespace Lean.IR.ExplicitRC /- Insert explicit RC instructions. So, it assumes the input code does not contain `inc` nor `dec` instructions. This transformation is applied before lower level optimizations that introduce the instructions `release` and `set` -/ structure VarInfo where ref : Bool := true -- true if the variable may be a reference (aka pointer) at runtime persistent : Bool := false -- true if the variable is statically known to be marked a Persistent at runtime consume : Bool := false -- true if the variable RC must be "consumed" deriving Inhabited abbrev VarMap := Std.RBMap VarId VarInfo (fun x y => x.idx < y.idx) structure Context where env : Environment decls : Array Decl varMap : VarMap := {} jpLiveVarMap : JPLiveVarMap := {} -- map: join point => live variables localCtx : LocalContext := {} -- we use it to store the join point declarations def getDecl (ctx : Context) (fid : FunId) : Decl := match findEnvDecl' ctx.env fid ctx.decls with | some decl => decl | none => unreachable! def getVarInfo (ctx : Context) (x : VarId) : VarInfo := match ctx.varMap.find? x with | some info => info | none => unreachable! def getJPParams (ctx : Context) (j : JoinPointId) : Array Param := match ctx.localCtx.getJPParams j with | some ps => ps | none => unreachable! def getJPLiveVars (ctx : Context) (j : JoinPointId) : LiveVarSet := match ctx.jpLiveVarMap.find? j with | some s => s | none => {} def mustConsume (ctx : Context) (x : VarId) : Bool := let info := getVarInfo ctx x info.ref && info.consume @[inline] def addInc (ctx : Context) (x : VarId) (b : FnBody) (n := 1) : FnBody := let info := getVarInfo ctx x if n == 0 then b else FnBody.inc x n true info.persistent b @[inline] def addDec (ctx : Context) (x : VarId) (b : FnBody) : FnBody := let info := getVarInfo ctx x FnBody.dec x 1 true info.persistent b private def updateRefUsingCtorInfo (ctx : Context) (x : VarId) (c : CtorInfo) : Context := if c.isRef then ctx else let m := ctx.varMap { ctx with varMap := match m.find? x with | some info => m.insert x { info with ref := false } -- I really want a Lenses library + notation | none => m } private def addDecForAlt (ctx : Context) (caseLiveVars altLiveVars : LiveVarSet) (b : FnBody) : FnBody := caseLiveVars.fold (init := b) fun b x => if !altLiveVars.contains x && mustConsume ctx x then addDec ctx x b else b /- `isFirstOcc xs x i = true` if `xs[i]` is the first occurrence of `xs[i]` in `xs` -/ private def isFirstOcc (xs : Array Arg) (i : Nat) : Bool := let x := xs[i] i.all fun j => xs[j] != x /- Return true if `x` also occurs in `ys` in a position that is not consumed. That is, it is also passed as a borrow reference. -/ @[specialize] private def isBorrowParamAux (x : VarId) (ys : Array Arg) (consumeParamPred : Nat → Bool) : Bool := ys.size.any fun i => let y := ys[i] match y with | Arg.irrelevant => false | Arg.var y => x == y && !consumeParamPred i private def isBorrowParam (x : VarId) (ys : Array Arg) (ps : Array Param) : Bool := isBorrowParamAux x ys fun i => not ps[i].borrow /- Return `n`, the number of times `x` is consumed. - `ys` is a sequence of instruction parameters where we search for `x`. - `consumeParamPred i = true` if parameter `i` is consumed. -/ @[specialize] private def getNumConsumptions (x : VarId) (ys : Array Arg) (consumeParamPred : Nat → Bool) : Nat := ys.size.fold (init := 0) fun i n => let y := ys[i] match y with | Arg.irrelevant => n | Arg.var y => if x == y && consumeParamPred i then n+1 else n @[specialize] private def addIncBeforeAux (ctx : Context) (xs : Array Arg) (consumeParamPred : Nat → Bool) (b : FnBody) (liveVarsAfter : LiveVarSet) : FnBody := xs.size.fold (init := b) fun i b => let x := xs[i] match x with | Arg.irrelevant => b | Arg.var x => let info := getVarInfo ctx x if !info.ref || !isFirstOcc xs i then b else let numConsuptions := getNumConsumptions x xs consumeParamPred -- number of times the argument is let numIncs := if !info.consume || -- `x` is not a variable that must be consumed by the current procedure liveVarsAfter.contains x || -- `x` is live after executing instruction isBorrowParamAux x xs consumeParamPred -- `x` is used in a position that is passed as a borrow reference then numConsuptions else numConsuptions - 1 -- dbgTrace ("addInc " ++ toString x ++ " nconsumptions: " ++ toString numConsuptions ++ " incs: " ++ toString numIncs -- ++ " consume: " ++ toString info.consume ++ " live: " ++ toString (liveVarsAfter.contains x) -- ++ " borrowParam : " ++ toString (isBorrowParamAux x xs consumeParamPred)) $ fun _ => addInc ctx x b numIncs private def addIncBefore (ctx : Context) (xs : Array Arg) (ps : Array Param) (b : FnBody) (liveVarsAfter : LiveVarSet) : FnBody := addIncBeforeAux ctx xs (fun i => not ps[i].borrow) b liveVarsAfter /- See `addIncBeforeAux`/`addIncBefore` for the procedure that inserts `inc` operations before an application. -/ private def addDecAfterFullApp (ctx : Context) (xs : Array Arg) (ps : Array Param) (b : FnBody) (bLiveVars : LiveVarSet) : FnBody := xs.size.fold (init := b) fun i b => match xs[i] with | Arg.irrelevant => b | Arg.var x => /- We must add a `dec` if `x` must be consumed, it is alive after the application, and it has been borrowed by the application. Remark: `x` may occur multiple times in the application (e.g., `f x y x`). This is why we check whether it is the first occurrence. -/ if mustConsume ctx x && isFirstOcc xs i && isBorrowParam x xs ps && !bLiveVars.contains x then addDec ctx x b else b private def addIncBeforeConsumeAll (ctx : Context) (xs : Array Arg) (b : FnBody) (liveVarsAfter : LiveVarSet) : FnBody := addIncBeforeAux ctx xs (fun i => true) b liveVarsAfter /- Add `dec` instructions for parameters that are references, are not alive in `b`, and are not borrow. That is, we must make sure these parameters are consumed. -/ private def addDecForDeadParams (ctx : Context) (ps : Array Param) (b : FnBody) (bLiveVars : LiveVarSet) : FnBody := ps.foldl (init := b) fun b p => if !p.borrow && p.ty.isObj && !bLiveVars.contains p.x then addDec ctx p.x b else b private def isPersistent : Expr → Bool | Expr.fap c xs => xs.isEmpty -- all global constants are persistent objects | _ => false /- We do not need to consume the projection of a variable that is not consumed -/ private def consumeExpr (m : VarMap) : Expr → Bool | Expr.proj i x => match m.find? x with | some info => info.consume | none => true | other => true /- Return true iff `v` at runtime is a scalar value stored in a tagged pointer. We do not need RC operations for this kind of value. -/ private def isScalarBoxedInTaggedPtr (v : Expr) : Bool := match v with | Expr.ctor c ys => c.size == 0 && c.ssize == 0 && c.usize == 0 | Expr.lit (LitVal.num n) => n ≤ maxSmallNat | _ => false private def updateVarInfo (ctx : Context) (x : VarId) (t : IRType) (v : Expr) : Context := { ctx with varMap := ctx.varMap.insert x { ref := t.isObj && !isScalarBoxedInTaggedPtr v, persistent := isPersistent v, consume := consumeExpr ctx.varMap v } } private def addDecIfNeeded (ctx : Context) (x : VarId) (b : FnBody) (bLiveVars : LiveVarSet) : FnBody := if mustConsume ctx x && !bLiveVars.contains x then addDec ctx x b else b private def processVDecl (ctx : Context) (z : VarId) (t : IRType) (v : Expr) (b : FnBody) (bLiveVars : LiveVarSet) : FnBody × LiveVarSet := let b := match v with | (Expr.ctor _ ys) => addIncBeforeConsumeAll ctx ys (FnBody.vdecl z t v b) bLiveVars | (Expr.reuse _ _ _ ys) => addIncBeforeConsumeAll ctx ys (FnBody.vdecl z t v b) bLiveVars | (Expr.proj _ x) => let b := addDecIfNeeded ctx x b bLiveVars let b := if (getVarInfo ctx x).consume then addInc ctx z b else b (FnBody.vdecl z t v b) | (Expr.uproj _ x) => FnBody.vdecl z t v (addDecIfNeeded ctx x b bLiveVars) | (Expr.sproj _ _ x) => FnBody.vdecl z t v (addDecIfNeeded ctx x b bLiveVars) | (Expr.fap f ys) => -- dbgTrace ("processVDecl " ++ toString v) $ fun _ => let ps := (getDecl ctx f).params let b := addDecAfterFullApp ctx ys ps b bLiveVars let b := FnBody.vdecl z t v b addIncBefore ctx ys ps b bLiveVars | (Expr.pap _ ys) => addIncBeforeConsumeAll ctx ys (FnBody.vdecl z t v b) bLiveVars | (Expr.ap x ys) => let ysx := ys.push (Arg.var x) -- TODO: avoid temporary array allocation addIncBeforeConsumeAll ctx ysx (FnBody.vdecl z t v b) bLiveVars | (Expr.unbox x) => FnBody.vdecl z t v (addDecIfNeeded ctx x b bLiveVars) | other => FnBody.vdecl z t v b -- Expr.reset, Expr.box, Expr.lit are handled here let liveVars := updateLiveVars v bLiveVars let liveVars := liveVars.erase z (b, liveVars) def updateVarInfoWithParams (ctx : Context) (ps : Array Param) : Context := let m := ps.foldl (init := ctx.varMap) fun m p => m.insert p.x { ref := p.ty.isObj, consume := !p.borrow } { ctx with varMap := m } partial def visitFnBody : FnBody → Context → (FnBody × LiveVarSet) | FnBody.vdecl x t v b, ctx => let ctx := updateVarInfo ctx x t v let (b, bLiveVars) := visitFnBody b ctx processVDecl ctx x t v b bLiveVars | FnBody.jdecl j xs v b, ctx => let ctxAtV := updateVarInfoWithParams ctx xs let (v, vLiveVars) := visitFnBody v ctxAtV let v := addDecForDeadParams ctxAtV xs v vLiveVars let ctx := { ctx with localCtx := ctx.localCtx.addJP j xs v jpLiveVarMap := updateJPLiveVarMap j xs v ctx.jpLiveVarMap } let (b, bLiveVars) := visitFnBody b ctx (FnBody.jdecl j xs v b, bLiveVars) | FnBody.uset x i y b, ctx => let (b, s) := visitFnBody b ctx -- We don't need to insert `y` since we only need to track live variables that are references at runtime let s := s.insert x (FnBody.uset x i y b, s) | FnBody.sset x i o y t b, ctx => let (b, s) := visitFnBody b ctx -- We don't need to insert `y` since we only need to track live variables that are references at runtime let s := s.insert x (FnBody.sset x i o y t b, s) | FnBody.mdata m b, ctx => let (b, s) := visitFnBody b ctx (FnBody.mdata m b, s) | b@(FnBody.case tid x xType alts), ctx => let caseLiveVars := collectLiveVars b ctx.jpLiveVarMap let alts := alts.map $ fun alt => match alt with | Alt.ctor c b => let ctx := updateRefUsingCtorInfo ctx x c let (b, altLiveVars) := visitFnBody b ctx let b := addDecForAlt ctx caseLiveVars altLiveVars b Alt.ctor c b | Alt.default b => let (b, altLiveVars) := visitFnBody b ctx let b := addDecForAlt ctx caseLiveVars altLiveVars b Alt.default b (FnBody.case tid x xType alts, caseLiveVars) | b@(FnBody.ret x), ctx => match x with | Arg.var x => let info := getVarInfo ctx x if info.ref && !info.consume then (addInc ctx x b, mkLiveVarSet x) else (b, mkLiveVarSet x) | _ => (b, {}) | b@(FnBody.jmp j xs), ctx => let jLiveVars := getJPLiveVars ctx j let ps := getJPParams ctx j let b := addIncBefore ctx xs ps b jLiveVars let bLiveVars := collectLiveVars b ctx.jpLiveVarMap (b, bLiveVars) | FnBody.unreachable, _ => (FnBody.unreachable, {}) | other, ctx => (other, {}) -- unreachable if well-formed partial def visitDecl (env : Environment) (decls : Array Decl) (d : Decl) : Decl := match d with | Decl.fdecl (xs := xs) (body := b) .. => let ctx : Context := { env := env, decls := decls } let ctx := updateVarInfoWithParams ctx xs let (b, bLiveVars) := visitFnBody b ctx let b := addDecForDeadParams ctx xs b bLiveVars d.updateBody! b | other => other end ExplicitRC def explicitRC (decls : Array Decl) : CompilerM (Array Decl) := do let env ← getEnv pure $ decls.map (ExplicitRC.visitDecl env decls) end Lean.IR
fc5f91672c05c8863e77e14d0d575b7f9538082b
1a61aba1b67cddccce19532a9596efe44be4285f
/library/data/int/order.lean
8916e982311533d841c7e394edcf0da9b4fcce5c
[ "Apache-2.0" ]
permissive
eigengrau/lean
07986a0f2548688c13ba36231f6cdbee82abf4c6
f8a773be1112015e2d232661ce616d23f12874d0
refs/heads/master
1,610,939,198,566
1,441,352,386,000
1,441,352,494,000
41,903,576
0
0
null
1,441,352,210,000
1,441,352,210,000
null
UTF-8
Lean
false
false
15,349
lean
/- Copyright (c) 2014 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Jeremy Avigad The order relation on the integers. We show that int is an instance of linear_comm_ordered_ring and transfer the results. -/ import .basic algebra.ordered_ring open nat open decidable open int eq.ops namespace int private definition nonneg (a : ℤ) : Prop := int.cases_on a (take n, true) (take n, false) definition le (a b : ℤ) : Prop := nonneg (b - a) definition lt (a b : ℤ) : Prop := le (a + 1) b infix [priority int.prio] - := int.sub infix [priority int.prio] <= := int.le infix [priority int.prio] ≤ := int.le infix [priority int.prio] < := int.lt local attribute nonneg [reducible] private definition decidable_nonneg [instance] (a : ℤ) : decidable (nonneg a) := int.cases_on a _ _ definition decidable_le [instance] (a b : ℤ) : decidable (a ≤ b) := decidable_nonneg _ definition decidable_lt [instance] (a b : ℤ) : decidable (a < b) := decidable_nonneg _ private theorem nonneg.elim {a : ℤ} : nonneg a → ∃n : ℕ, a = n := int.cases_on a (take n H, exists.intro n rfl) (take n', false.elim) private theorem nonneg_or_nonneg_neg (a : ℤ) : nonneg a ∨ nonneg (-a) := int.cases_on a (take n, or.inl trivial) (take n, or.inr trivial) theorem le.intro {a b : ℤ} {n : ℕ} (H : a + n = b) : a ≤ b := have n = b - a, from eq_add_neg_of_add_eq (!add.comm ▸ H), show nonneg (b - a), from this ▸ trivial theorem le.elim {a b : ℤ} (H : a ≤ b) : ∃n : ℕ, a + n = b := obtain (n : ℕ) (H1 : b - a = n), from nonneg.elim H, exists.intro n (!add.comm ▸ iff.mpr !add_eq_iff_eq_add_neg (H1⁻¹)) theorem le.total (a b : ℤ) : a ≤ b ∨ b ≤ a := or.imp_right (assume H : nonneg (-(b - a)), have -(b - a) = a - b, from !neg_sub, show nonneg (a - b), from this ▸ H) -- too bad: can't do it in one step (nonneg_or_nonneg_neg (b - a)) theorem of_nat_le_of_nat_of_le {m n : ℕ} (H : #nat m ≤ n) : of_nat m ≤ of_nat n := obtain (k : ℕ) (Hk : m + k = n), from nat.le.elim H, le.intro (Hk ▸ (of_nat_add m k)⁻¹) theorem le_of_of_nat_le_of_nat {m n : ℕ} (H : of_nat m ≤ of_nat n) : (#nat m ≤ n) := obtain (k : ℕ) (Hk : of_nat m + of_nat k = of_nat n), from le.elim H, have m + k = n, from of_nat.inj (of_nat_add m k ⬝ Hk), nat.le.intro this theorem of_nat_le_of_nat (m n : ℕ) : of_nat m ≤ of_nat n ↔ m ≤ n := iff.intro le_of_of_nat_le_of_nat of_nat_le_of_nat_of_le theorem lt_add_succ (a : ℤ) (n : ℕ) : a < a + succ n := le.intro (show a + 1 + n = a + succ n, from calc a + 1 + n = a + (1 + n) : add.assoc ... = a + (n + 1) : nat.add.comm ... = a + succ n : rfl) theorem lt.intro {a b : ℤ} {n : ℕ} (H : a + succ n = b) : a < b := H ▸ lt_add_succ a n theorem lt.elim {a b : ℤ} (H : a < b) : ∃n : ℕ, a + succ n = b := obtain (n : ℕ) (Hn : a + 1 + n = b), from le.elim H, have a + succ n = b, from calc a + succ n = a + 1 + n : by rewrite [add.assoc, add.comm 1 n] ... = b : Hn, exists.intro n this theorem of_nat_lt_of_nat (n m : ℕ) : of_nat n < of_nat m ↔ n < m := calc of_nat n < of_nat m ↔ of_nat n + 1 ≤ of_nat m : iff.refl ... ↔ of_nat (nat.succ n) ≤ of_nat m : of_nat_succ n ▸ !iff.refl ... ↔ nat.succ n ≤ m : of_nat_le_of_nat ... ↔ n < m : iff.symm (lt_iff_succ_le _ _) theorem lt_of_of_nat_lt_of_nat {m n : ℕ} (H : of_nat m < of_nat n) : #nat m < n := iff.mp !of_nat_lt_of_nat H theorem of_nat_lt_of_nat_of_lt {m n : ℕ} (H : #nat m < n) : of_nat m < of_nat n := iff.mpr !of_nat_lt_of_nat H /- show that the integers form an ordered additive group -/ theorem le.refl (a : ℤ) : a ≤ a := le.intro (add_zero a) theorem le.trans {a b c : ℤ} (H1 : a ≤ b) (H2 : b ≤ c) : a ≤ c := obtain (n : ℕ) (Hn : a + n = b), from le.elim H1, obtain (m : ℕ) (Hm : b + m = c), from le.elim H2, have a + of_nat (n + m) = c, from calc a + of_nat (n + m) = a + (of_nat n + m) : {of_nat_add n m} ... = a + n + m : (add.assoc a n m)⁻¹ ... = b + m : {Hn} ... = c : Hm, le.intro this theorem le.antisymm : ∀ {a b : ℤ}, a ≤ b → b ≤ a → a = b := take a b : ℤ, assume (H₁ : a ≤ b) (H₂ : b ≤ a), obtain (n : ℕ) (Hn : a + n = b), from le.elim H₁, obtain (m : ℕ) (Hm : b + m = a), from le.elim H₂, have a + of_nat (n + m) = a + 0, from calc a + of_nat (n + m) = a + (of_nat n + m) : of_nat_add ... = a + n + m : add.assoc ... = b + m : Hn ... = a : Hm ... = a + 0 : add_zero, have of_nat (n + m) = of_nat 0, from add.left_cancel this, have n + m = 0, from of_nat.inj this, have n = 0, from nat.eq_zero_of_add_eq_zero_right this, show a = b, from calc a = a + 0 : add_zero ... = a + n : this ... = b : Hn theorem lt.irrefl (a : ℤ) : ¬ a < a := (suppose a < a, obtain (n : ℕ) (Hn : a + succ n = a), from lt.elim this, have a + succ n = a + 0, from Hn ⬝ !add_zero⁻¹, !succ_ne_zero (of_nat.inj (add.left_cancel this))) theorem ne_of_lt {a b : ℤ} (H : a < b) : a ≠ b := (suppose a = b, absurd (this ▸ H) (lt.irrefl b)) theorem le_of_lt {a b : ℤ} (H : a < b) : a ≤ b := obtain (n : ℕ) (Hn : a + succ n = b), from lt.elim H, le.intro Hn theorem lt_iff_le_and_ne (a b : ℤ) : a < b ↔ (a ≤ b ∧ a ≠ b) := iff.intro (assume H, and.intro (le_of_lt H) (ne_of_lt H)) (assume H, have a ≤ b, from and.elim_left H, have a ≠ b, from and.elim_right H, obtain (n : ℕ) (Hn : a + n = b), from le.elim `a ≤ b`, have n ≠ 0, from (assume H' : n = 0, `a ≠ b` (!add_zero ▸ H' ▸ Hn)), obtain (k : ℕ) (Hk : n = nat.succ k), from nat.exists_eq_succ_of_ne_zero this, lt.intro (Hk ▸ Hn)) theorem le_iff_lt_or_eq (a b : ℤ) : a ≤ b ↔ (a < b ∨ a = b) := iff.intro (assume H, by_cases (suppose a = b, or.inr this) (suppose a ≠ b, obtain (n : ℕ) (Hn : a + n = b), from le.elim H, have n ≠ 0, from (assume H' : n = 0, `a ≠ b` (!add_zero ▸ H' ▸ Hn)), obtain (k : ℕ) (Hk : n = nat.succ k), from nat.exists_eq_succ_of_ne_zero this, or.inl (lt.intro (Hk ▸ Hn)))) (assume H, or.elim H (assume H1, le_of_lt H1) (assume H1, H1 ▸ !le.refl)) theorem lt_succ (a : ℤ) : a < a + 1 := le.refl (a + 1) theorem add_le_add_left {a b : ℤ} (H : a ≤ b) (c : ℤ) : c + a ≤ c + b := obtain (n : ℕ) (Hn : a + n = b), from le.elim H, have H2 : c + a + n = c + b, from calc c + a + n = c + (a + n) : add.assoc c a n ... = c + b : {Hn}, le.intro H2 theorem add_lt_add_left {a b : ℤ} (H : a < b) (c : ℤ) : c + a < c + b := let H' := le_of_lt H in (iff.mpr (lt_iff_le_and_ne _ _)) (and.intro (add_le_add_left H' _) (take Heq, let Heq' := add_left_cancel Heq in !lt.irrefl (Heq' ▸ H))) theorem mul_nonneg {a b : ℤ} (Ha : 0 ≤ a) (Hb : 0 ≤ b) : 0 ≤ a * b := obtain (n : ℕ) (Hn : 0 + n = a), from le.elim Ha, obtain (m : ℕ) (Hm : 0 + m = b), from le.elim Hb, le.intro (eq.symm (calc a * b = (0 + n) * b : Hn ... = n * b : nat.zero_add ... = n * (0 + m) : {Hm⁻¹} ... = n * m : nat.zero_add ... = 0 + n * m : zero_add)) theorem mul_pos {a b : ℤ} (Ha : 0 < a) (Hb : 0 < b) : 0 < a * b := obtain (n : ℕ) (Hn : 0 + nat.succ n = a), from lt.elim Ha, obtain (m : ℕ) (Hm : 0 + nat.succ m = b), from lt.elim Hb, lt.intro (eq.symm (calc a * b = (0 + nat.succ n) * b : Hn ... = nat.succ n * b : nat.zero_add ... = nat.succ n * (0 + nat.succ m) : {Hm⁻¹} ... = nat.succ n * nat.succ m : nat.zero_add ... = of_nat (nat.succ n * nat.succ m) : of_nat_mul ... = of_nat (nat.succ n * m + nat.succ n) : nat.mul_succ ... = of_nat (nat.succ (nat.succ n * m + n)) : nat.add_succ ... = 0 + nat.succ (nat.succ n * m + n) : zero_add)) theorem zero_lt_one : (0 : ℤ) < 1 := trivial theorem not_le_of_gt {a b : ℤ} (H : a < b) : ¬ b ≤ a := assume Hba, let Heq := le.antisymm (le_of_lt H) Hba in !lt.irrefl (Heq ▸ H) theorem lt_of_lt_of_le {a b c : ℤ} (Hab : a < b) (Hbc : b ≤ c) : a < c := let Hab' := le_of_lt Hab in let Hac := le.trans Hab' Hbc in (iff.mpr !lt_iff_le_and_ne) (and.intro Hac (assume Heq, not_le_of_gt (Heq ▸ Hab) Hbc)) theorem lt_of_le_of_lt {a b c : ℤ} (Hab : a ≤ b) (Hbc : b < c) : a < c := let Hbc' := le_of_lt Hbc in let Hac := le.trans Hab Hbc' in (iff.mpr !lt_iff_le_and_ne) (and.intro Hac (assume Heq, not_le_of_gt (Heq⁻¹ ▸ Hbc) Hab)) section migrate_algebra open [classes] algebra protected definition linear_ordered_comm_ring [reducible] : algebra.linear_ordered_comm_ring int := ⦃algebra.linear_ordered_comm_ring, int.integral_domain, le := le, le_refl := le.refl, le_trans := @le.trans, le_antisymm := @le.antisymm, lt := lt, le_of_lt := @le_of_lt, lt_irrefl := lt.irrefl, lt_of_lt_of_le := @lt_of_lt_of_le, lt_of_le_of_lt := @lt_of_le_of_lt, add_le_add_left := @add_le_add_left, mul_nonneg := @mul_nonneg, mul_pos := @mul_pos, le_iff_lt_or_eq := le_iff_lt_or_eq, le_total := le.total, zero_ne_one := zero_ne_one, zero_lt_one := zero_lt_one, add_lt_add_left := @add_lt_add_left⦄ protected definition decidable_linear_ordered_comm_ring [reducible] : algebra.decidable_linear_ordered_comm_ring int := ⦃algebra.decidable_linear_ordered_comm_ring, int.linear_ordered_comm_ring, decidable_lt := decidable_lt⦄ local attribute int.integral_domain [instance] local attribute int.linear_ordered_comm_ring [instance] local attribute int.decidable_linear_ordered_comm_ring [instance] definition ge [reducible] (a b : ℤ) := algebra.has_le.ge a b definition gt [reducible] (a b : ℤ) := algebra.has_lt.gt a b infix [priority int.prio] >= := int.ge infix [priority int.prio] ≥ := int.ge infix [priority int.prio] > := int.gt definition decidable_ge [instance] (a b : ℤ) : decidable (a ≥ b) := show decidable (b ≤ a), from _ definition decidable_gt [instance] (a b : ℤ) : decidable (a > b) := show decidable (b < a), from _ definition min : ℤ → ℤ → ℤ := algebra.min definition max : ℤ → ℤ → ℤ := algebra.max definition abs : ℤ → ℤ := algebra.abs definition sign : ℤ → ℤ := algebra.sign migrate from algebra with int replacing dvd → dvd, sub → sub, has_le.ge → ge, has_lt.gt → gt, min → min, max → max, abs → abs, sign → sign attribute le.trans ge.trans lt.trans gt.trans [trans] attribute lt_of_lt_of_le lt_of_le_of_lt gt_of_gt_of_ge gt_of_ge_of_gt [trans] end migrate_algebra /- more facts specific to int -/ theorem of_nat_nonneg (n : ℕ) : 0 ≤ of_nat n := trivial theorem of_nat_pos {n : ℕ} (Hpos : #nat n > 0) : of_nat n > 0 := of_nat_lt_of_nat_of_lt Hpos theorem of_nat_succ_pos (n : nat) : of_nat (nat.succ n) > 0 := of_nat_pos !nat.succ_pos theorem exists_eq_of_nat {a : ℤ} (H : 0 ≤ a) : ∃n : ℕ, a = of_nat n := obtain (n : ℕ) (H1 : 0 + of_nat n = a), from le.elim H, exists.intro n (!zero_add ▸ (H1⁻¹)) theorem exists_eq_neg_of_nat {a : ℤ} (H : a ≤ 0) : ∃n : ℕ, a = -(of_nat n) := have -a ≥ 0, from iff.mpr !neg_nonneg_iff_nonpos H, obtain (n : ℕ) (Hn : -a = of_nat n), from exists_eq_of_nat this, exists.intro n (eq_neg_of_eq_neg (Hn⁻¹)) theorem of_nat_nat_abs_of_nonneg {a : ℤ} (H : a ≥ 0) : of_nat (nat_abs a) = a := obtain (n : ℕ) (Hn : a = of_nat n), from exists_eq_of_nat H, Hn⁻¹ ▸ congr_arg of_nat (nat_abs_of_nat n) theorem of_nat_nat_abs_of_nonpos {a : ℤ} (H : a ≤ 0) : of_nat (nat_abs a) = -a := have -a ≥ 0, from iff.mpr !neg_nonneg_iff_nonpos H, calc of_nat (nat_abs a) = of_nat (nat_abs (-a)) : nat_abs_neg ... = -a : of_nat_nat_abs_of_nonneg this theorem of_nat_nat_abs (b : ℤ) : nat_abs b = abs b := or.elim (le.total 0 b) (assume H : b ≥ 0, of_nat_nat_abs_of_nonneg H ⬝ (abs_of_nonneg H)⁻¹) (assume H : b ≤ 0, of_nat_nat_abs_of_nonpos H ⬝ (abs_of_nonpos H)⁻¹) theorem nat_abs_abs (a : ℤ) : nat_abs (abs a) = nat_abs a := abs.by_cases rfl !nat_abs_neg theorem lt_of_add_one_le {a b : ℤ} (H : a + 1 ≤ b) : a < b := obtain n (H1 : a + 1 + n = b), from le.elim H, have a + succ n = b, by rewrite [-H1, add.assoc, add.comm 1], lt.intro this theorem add_one_le_of_lt {a b : ℤ} (H : a < b) : a + 1 ≤ b := obtain n (H1 : a + succ n = b), from lt.elim H, have a + 1 + n = b, by rewrite [-H1, add.assoc, add.comm 1], le.intro this theorem lt_add_one_of_le {a b : ℤ} (H : a ≤ b) : a < b + 1 := lt_add_of_le_of_pos H trivial theorem le_of_lt_add_one {a b : ℤ} (H : a < b + 1) : a ≤ b := have H1 : a + 1 ≤ b + 1, from add_one_le_of_lt H, le_of_add_le_add_right H1 theorem sub_one_le_of_lt {a b : ℤ} (H : a ≤ b) : a - 1 < b := lt_of_add_one_le (!sub_add_cancel⁻¹ ▸ H) theorem lt_of_sub_one_le {a b : ℤ} (H : a - 1 < b) : a ≤ b := !sub_add_cancel ▸ add_one_le_of_lt H theorem le_sub_one_of_lt {a b : ℤ} (H : a < b) : a ≤ b - 1 := le_of_lt_add_one (!sub_add_cancel⁻¹ ▸ H) theorem lt_of_le_sub_one {a b : ℤ} (H : a ≤ b - 1) : a < b := !sub_add_cancel ▸ (lt_add_one_of_le H) theorem sign_of_succ (n : nat) : sign (nat.succ n) = 1 := sign_of_pos (of_nat_pos !nat.succ_pos) theorem exists_eq_neg_succ_of_nat {a : ℤ} : a < 0 → ∃m : ℕ, a = -[1+m] := int.cases_on a (take m H, absurd (of_nat_nonneg m : 0 ≤ m) (not_le_of_gt H)) (take m H, exists.intro m rfl) theorem eq_one_of_mul_eq_one_right {a b : ℤ} (H : a ≥ 0) (H' : a * b = 1) : a = 1 := have a * b > 0, by rewrite H'; apply trivial, have b > 0, from pos_of_mul_pos_left this H, have a > 0, from pos_of_mul_pos_right `a * b > 0` (le_of_lt `b > 0`), or.elim (le_or_gt a 1) (suppose a ≤ 1, show a = 1, from le.antisymm this (add_one_le_of_lt `a > 0`)) (suppose a > 1, assert a * b ≥ 2 * 1, from mul_le_mul (add_one_le_of_lt `a > 1`) (add_one_le_of_lt `b > 0`) trivial H, have false, by rewrite [H' at this]; exact this, false.elim this) theorem eq_one_of_mul_eq_one_left {a b : ℤ} (H : b ≥ 0) (H' : a * b = 1) : b = 1 := eq_one_of_mul_eq_one_right H (!mul.comm ▸ H') theorem eq_one_of_mul_eq_self_left {a b : ℤ} (Hpos : a ≠ 0) (H : b * a = a) : b = 1 := eq_of_mul_eq_mul_right Hpos (H ⬝ (one_mul a)⁻¹) theorem eq_one_of_mul_eq_self_right {a b : ℤ} (Hpos : b ≠ 0) (H : b * a = b) : a = 1 := eq_one_of_mul_eq_self_left Hpos (!mul.comm ▸ H) theorem eq_one_of_dvd_one {a : ℤ} (H : a ≥ 0) (H' : a ∣ 1) : a = 1 := dvd.elim H' (take b, suppose 1 = a * b, eq_one_of_mul_eq_one_right H this⁻¹) end int
59676a84c22ba680153179681ae2b1773e9423fc
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/algebra/floor_auto.lean
4365294ab28314ff9c05803033fa5811a2bcde8c
[]
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
12,139
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kevin Kappelmann -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.tactic.linarith.default import Mathlib.tactic.abel import Mathlib.algebra.ordered_group import Mathlib.data.set.intervals.basic import Mathlib.PostPort universes u_2 l u_1 namespace Mathlib /-! # Floor and Ceil ## Summary We define `floor`, `ceil`, and `nat_ceil` functions on linear ordered rings. ## Main Definitions - `floor_ring` is a linear ordered ring with floor function. - `floor x` is the greatest integer `z` such that `z ≤ x`. - `fract x` is the fractional part of x, that is `x - floor x`. - `ceil x` is the smallest integer `z` such that `x ≤ z`. - `nat_ceil x` is the smallest nonnegative integer `n` with `x ≤ n`. ## Notations - `⌊x⌋` is `floor x`. - `⌈x⌉` is `ceil x`. ## Tags rounding -/ /-- A `floor_ring` is a linear ordered ring over `α` with a function `floor : α → ℤ` satisfying `∀ (z : ℤ) (x : α), z ≤ floor x ↔ (z : α) ≤ x)`. -/ class floor_ring (α : Type u_2) [linear_ordered_ring α] where floor : α → ℤ le_floor : ∀ (z : ℤ) (x : α), z ≤ floor x ↔ ↑z ≤ x protected instance int.floor_ring : floor_ring ℤ := floor_ring.mk id sorry /-- `floor x` is the greatest integer `z` such that `z ≤ x` -/ def floor {α : Type u_1} [linear_ordered_ring α] [floor_ring α] : α → ℤ := floor_ring.floor theorem le_floor {α : Type u_1} [linear_ordered_ring α] [floor_ring α] {z : ℤ} {x : α} : z ≤ floor x ↔ ↑z ≤ x := floor_ring.le_floor theorem floor_lt {α : Type u_1} [linear_ordered_ring α] [floor_ring α] {x : α} {z : ℤ} : floor x < z ↔ x < ↑z := lt_iff_lt_of_le_iff_le le_floor theorem floor_le {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (x : α) : ↑(floor x) ≤ x := iff.mp le_floor (le_refl (floor x)) theorem floor_nonneg {α : Type u_1} [linear_ordered_ring α] [floor_ring α] {x : α} : 0 ≤ floor x ↔ 0 ≤ x := eq.mpr (id (Eq._oldrec (Eq.refl (0 ≤ floor x ↔ 0 ≤ x)) (propext le_floor))) (iff.refl (↑0 ≤ x)) theorem lt_succ_floor {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (x : α) : x < ↑(int.succ (floor x)) := iff.mp floor_lt (int.lt_succ_self (floor x)) theorem lt_floor_add_one {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (x : α) : x < ↑(floor x) + 1 := sorry theorem sub_one_lt_floor {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (x : α) : x - 1 < ↑(floor x) := iff.mpr sub_lt_iff_lt_add (lt_floor_add_one x) @[simp] theorem floor_coe {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (z : ℤ) : floor ↑z = z := sorry @[simp] theorem floor_zero {α : Type u_1} [linear_ordered_ring α] [floor_ring α] : floor 0 = 0 := floor_coe 0 @[simp] theorem floor_one {α : Type u_1} [linear_ordered_ring α] [floor_ring α] : floor 1 = 1 := eq.mpr (id (Eq._oldrec (Eq.refl (floor 1 = 1)) (Eq.symm int.cast_one))) (eq.mpr (id (Eq._oldrec (Eq.refl (floor ↑1 = 1)) (floor_coe 1))) (Eq.refl 1)) theorem floor_mono {α : Type u_1} [linear_ordered_ring α] [floor_ring α] {a : α} {b : α} (h : a ≤ b) : floor a ≤ floor b := iff.mpr le_floor (le_trans (floor_le a) h) @[simp] theorem floor_add_int {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (x : α) (z : ℤ) : floor (x + ↑z) = floor x + z := sorry theorem floor_sub_int {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (x : α) (z : ℤ) : floor (x - ↑z) = floor x - z := sorry theorem abs_sub_lt_one_of_floor_eq_floor {α : Type u_1} [linear_ordered_comm_ring α] [floor_ring α] {x : α} {y : α} (h : floor x = floor y) : abs (x - y) < 1 := sorry theorem floor_eq_iff {α : Type u_1} [linear_ordered_ring α] [floor_ring α] {r : α} {z : ℤ} : floor r = z ↔ ↑z ≤ r ∧ r < ↑z + 1 := sorry theorem floor_ring_unique {α : Type u_1} [linear_ordered_ring α] (inst1 : floor_ring α) (inst2 : floor_ring α) : floor = floor := sorry theorem floor_eq_on_Ico {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (n : ℤ) (x : α) (H : x ∈ set.Ico (↑n) (↑n + 1)) : floor x = n := sorry theorem floor_eq_on_Ico' {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (n : ℤ) (x : α) (H : x ∈ set.Ico (↑n) (↑n + 1)) : ↑(floor x) = ↑n := eq.mpr (id (propext int.cast_inj)) (floor_eq_on_Ico n x hx) /-- The fractional part fract r of r is just r - ⌊r⌋ -/ def fract {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (r : α) : α := r - ↑(floor r) -- Mathematical notation is usually {r}. Let's not even go there. @[simp] theorem floor_add_fract {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (r : α) : ↑(floor r) + fract r = r := sorry @[simp] theorem fract_add_floor {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (r : α) : fract r + ↑(floor r) = r := sub_add_cancel r ↑(floor r) theorem fract_nonneg {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (r : α) : 0 ≤ fract r := iff.mpr sub_nonneg (floor_le r) theorem fract_lt_one {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (r : α) : fract r < 1 := iff.mp sub_lt (sub_one_lt_floor r) @[simp] theorem fract_zero {α : Type u_1} [linear_ordered_ring α] [floor_ring α] : fract 0 = 0 := sorry @[simp] theorem fract_coe {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (z : ℤ) : fract ↑z = 0 := sorry @[simp] theorem fract_floor {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (r : α) : fract ↑(floor r) = 0 := fract_coe (floor r) @[simp] theorem floor_fract {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (r : α) : floor (fract r) = 0 := sorry theorem fract_eq_iff {α : Type u_1} [linear_ordered_ring α] [floor_ring α] {r : α} {s : α} : fract r = s ↔ 0 ≤ s ∧ s < 1 ∧ ∃ (z : ℤ), r - s = ↑z := sorry theorem fract_eq_fract {α : Type u_1} [linear_ordered_ring α] [floor_ring α] {r : α} {s : α} : fract r = fract s ↔ ∃ (z : ℤ), r - s = ↑z := sorry @[simp] theorem fract_fract {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (r : α) : fract (fract r) = fract r := sorry theorem fract_add {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (r : α) (s : α) : ∃ (z : ℤ), fract (r + s) - fract r - fract s = ↑z := sorry theorem fract_mul_nat {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (r : α) (b : ℕ) : ∃ (z : ℤ), fract r * ↑b - fract (r * ↑b) = ↑z := sorry /-- `ceil x` is the smallest integer `z` such that `x ≤ z` -/ def ceil {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (x : α) : ℤ := -floor (-x) theorem ceil_le {α : Type u_1} [linear_ordered_ring α] [floor_ring α] {z : ℤ} {x : α} : ceil x ≤ z ↔ x ≤ ↑z := sorry theorem lt_ceil {α : Type u_1} [linear_ordered_ring α] [floor_ring α] {x : α} {z : ℤ} : z < ceil x ↔ ↑z < x := lt_iff_lt_of_le_iff_le ceil_le theorem ceil_le_floor_add_one {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (x : α) : ceil x ≤ floor x + 1 := eq.mpr (id (Eq._oldrec (Eq.refl (ceil x ≤ floor x + 1)) (propext ceil_le))) (eq.mpr (id (Eq._oldrec (Eq.refl (x ≤ ↑(floor x + 1))) (int.cast_add (floor x) 1))) (eq.mpr (id (Eq._oldrec (Eq.refl (x ≤ ↑(floor x) + ↑1)) int.cast_one)) (le_of_lt (lt_floor_add_one x)))) theorem le_ceil {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (x : α) : x ≤ ↑(ceil x) := iff.mp ceil_le (le_refl (ceil x)) @[simp] theorem ceil_coe {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (z : ℤ) : ceil ↑z = z := sorry theorem ceil_mono {α : Type u_1} [linear_ordered_ring α] [floor_ring α] {a : α} {b : α} (h : a ≤ b) : ceil a ≤ ceil b := iff.mpr ceil_le (le_trans h (le_ceil b)) @[simp] theorem ceil_add_int {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (x : α) (z : ℤ) : ceil (x + ↑z) = ceil x + z := sorry theorem ceil_sub_int {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (x : α) (z : ℤ) : ceil (x - ↑z) = ceil x - z := sorry theorem ceil_lt_add_one {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (x : α) : ↑(ceil x) < x + 1 := eq.mpr (id (Eq._oldrec (Eq.refl (↑(ceil x) < x + 1)) (Eq.symm (propext lt_ceil)))) (eq.mpr (id (Eq._oldrec (Eq.refl (ceil x < ceil (x + 1))) (Eq.symm int.cast_one))) (eq.mpr (id (Eq._oldrec (Eq.refl (ceil x < ceil (x + ↑1))) (ceil_add_int x 1))) (lt_add_one (ceil x)))) theorem ceil_pos {α : Type u_1} [linear_ordered_ring α] [floor_ring α] {a : α} : 0 < ceil a ↔ 0 < a := sorry @[simp] theorem ceil_zero {α : Type u_1} [linear_ordered_ring α] [floor_ring α] : ceil 0 = 0 := sorry theorem ceil_nonneg {α : Type u_1} [linear_ordered_ring α] [floor_ring α] {q : α} (hq : 0 ≤ q) : 0 ≤ ceil q := sorry theorem ceil_eq_iff {α : Type u_1} [linear_ordered_ring α] [floor_ring α] {r : α} {z : ℤ} : ceil r = z ↔ ↑z - 1 < r ∧ r ≤ ↑z := sorry theorem ceil_eq_on_Ioc {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (n : ℤ) (x : α) (H : x ∈ set.Ioc (↑n - 1) ↑n) : ceil x = n := sorry theorem ceil_eq_on_Ioc' {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (n : ℤ) (x : α) (H : x ∈ set.Ioc (↑n - 1) ↑n) : ↑(ceil x) = ↑n := eq.mpr (id (propext int.cast_inj)) (ceil_eq_on_Ioc n x hx) /-- `nat_ceil x` is the smallest nonnegative integer `n` with `x ≤ n`. It is the same as `⌈q⌉` when `q ≥ 0`, otherwise it is `0`. -/ def nat_ceil {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (a : α) : ℕ := int.to_nat (ceil a) theorem nat_ceil_le {α : Type u_1} [linear_ordered_ring α] [floor_ring α] {a : α} {n : ℕ} : nat_ceil a ≤ n ↔ a ≤ ↑n := eq.mpr (id (Eq._oldrec (Eq.refl (nat_ceil a ≤ n ↔ a ≤ ↑n)) (nat_ceil.equations._eqn_1 a))) (eq.mpr (id (Eq._oldrec (Eq.refl (int.to_nat (ceil a) ≤ n ↔ a ≤ ↑n)) (propext int.to_nat_le))) (eq.mpr (id (Eq._oldrec (Eq.refl (ceil a ≤ ↑n ↔ a ≤ ↑n)) (propext ceil_le))) (iff.refl (a ≤ ↑↑n)))) theorem lt_nat_ceil {α : Type u_1} [linear_ordered_ring α] [floor_ring α] {a : α} {n : ℕ} : n < nat_ceil a ↔ ↑n < a := sorry theorem le_nat_ceil {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (a : α) : a ≤ ↑(nat_ceil a) := iff.mp nat_ceil_le (le_refl (nat_ceil a)) theorem nat_ceil_mono {α : Type u_1} [linear_ordered_ring α] [floor_ring α] {a₁ : α} {a₂ : α} (h : a₁ ≤ a₂) : nat_ceil a₁ ≤ nat_ceil a₂ := iff.mpr nat_ceil_le (le_trans h (le_nat_ceil a₂)) @[simp] theorem nat_ceil_coe {α : Type u_1} [linear_ordered_ring α] [floor_ring α] (n : ℕ) : nat_ceil ↑n = n := (fun (this : int.to_nat (ceil ↑↑n) = n) => this) (eq.mpr (id (Eq._oldrec (Eq.refl (int.to_nat (ceil ↑↑n) = n)) (ceil_coe ↑n))) (Eq.refl (int.to_nat ↑n))) @[simp] theorem nat_ceil_zero {α : Type u_1} [linear_ordered_ring α] [floor_ring α] : nat_ceil 0 = 0 := nat_ceil_coe 0 theorem nat_ceil_add_nat {α : Type u_1} [linear_ordered_ring α] [floor_ring α] {a : α} (a_nonneg : 0 ≤ a) (n : ℕ) : nat_ceil (a + ↑n) = nat_ceil a + n := sorry theorem nat_ceil_lt_add_one {α : Type u_1} [linear_ordered_ring α] [floor_ring α] {a : α} (a_nonneg : 0 ≤ a) : ↑(nat_ceil a) < a + 1 := sorry theorem lt_of_nat_ceil_lt {α : Type u_1} [linear_ordered_ring α] [floor_ring α] {x : α} {n : ℕ} (h : nat_ceil x < n) : x < ↑n := lt_of_le_of_lt (le_nat_ceil x) (eq.mpr (id (propext nat.cast_lt)) h) theorem le_of_nat_ceil_le {α : Type u_1} [linear_ordered_ring α] [floor_ring α] {x : α} {n : ℕ} (h : nat_ceil x ≤ n) : x ≤ ↑n := le_trans (le_nat_ceil x) (eq.mpr (id (propext nat.cast_le)) h) end Mathlib
283bab0ffe361d06965fc35903f126f6771eed48
aa3f8992ef7806974bc1ffd468baa0c79f4d6643
/library/data/bool/decl.lean
6eac93fb4d9bca40e5acd2b5ba0b9d81b2de5b1e
[ "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
239
lean
-- Copyright (c) 2014 Microsoft Corporation. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Author: Leonardo de Moura import data.unit.decl inductive bool : Type := ff : bool, tt : bool
4ecc254c626b1aecc040091cbda10ea4b21f52ce
e1440579fb0723caf9edf1ed07aee74bbf4f5ce7
/lean-experiments/stumps-learnable/src/lib/attributed/probability_theory.lean
a712d7730e8f6f3fe3a0f1001c4ebaf9b81531b6
[ "Apache-2.0" ]
permissive
palmskog/coq-proba
1ecc5b7f399894ea14d6094a31a063280a122099
f73e2780871e2a3dd83b7ce9d3aed19f499f07e5
refs/heads/master
1,599,620,504,720
1,572,960,008,000
1,572,960,008,000
221,326,479
0
0
Apache-2.0
1,573,598,769,000
1,573,598,768,000
null
UTF-8
Lean
false
false
18,078
lean
/- Probability theory generalities. Some parts of this file are originally from https://github.com/johoelzl/mathlib/blob/c9507242274ac18defbceb917f30d6afb8b839a5/src/probability_theory/basic.lean Authors: Johannes Holzl, Koundinya Vajjha -/ import measure_theory.measure_space tactic.tidy measure_theory.giry_monad local attribute [instance] classical.prop_decidable noncomputable theory open measure_theory ennreal lattice measure_theory measure_theory.measure set universe u section variables (α : Type*) [measurable_space α] structure probability_measure extends measure_theory.measure α := (measure_univ : to_measure univ = 1) instance : measurable_space (probability_measure α) := measure.measurable_space.comap probability_measure.to_measure lemma measurable_to_measure : measurable (@probability_measure.to_measure α _) := measurable_space.le_map_comap instance prob_measure_coe : has_coe (probability_measure α) (measure α) := ⟨probability_measure.to_measure⟩ instance : has_coe_to_fun (probability_measure α) := ⟨λ_, set α → nnreal, λp s, ennreal.to_nnreal (p.to_measure s)⟩ end namespace probability_measure section parameters {α : Type*} [measurable_space α] (p : probability_measure α) lemma to_measure_lt_top (s : set α) : p.to_measure s < ⊤ := lt_of_le_of_lt (measure_mono $ subset_univ s) $ p.measure_univ.symm ▸ coe_lt_top lemma to_measure_ne_top (s : set α) : p.to_measure s ≠ ⊤ := lt_top_iff_ne_top.1 (to_measure_lt_top s) lemma coe_eq_to_measure (s : set α) : (p s : ennreal) = p.to_measure s := coe_to_nnreal (to_measure_ne_top s) @[simp] lemma prob_apply {α : Type u} [measurable_space α] {s : set α}(hs : is_measurable s) (p : probability_measure α) : (p : probability_measure α) s = ennreal.to_nnreal (p.to_measure s) := rfl @[extensionality] lemma prob.ext {α} [measurable_space α] : ∀ {μ₁ μ₂ : probability_measure α}, (∀s, is_measurable s → μ₁ s = μ₂ s) → μ₁ = μ₂ | ⟨m₁, u₁⟩ ⟨m₂, u₂⟩ H := begin congr, refine measure.ext (λ s hs, _), have : (ennreal.to_nnreal (m₁ s) : ennreal) = ennreal.to_nnreal (m₂ s) := congr_arg coe (H s hs), rwa [coe_to_nnreal, coe_to_nnreal] at this, apply lt_top_iff_ne_top.1 (lt_of_le_of_lt (measure_mono $ subset_univ s) $ by rw u₂ ; exact ennreal.lt_top_iff_ne_top.2 one_ne_top), apply lt_top_iff_ne_top.1 (lt_of_le_of_lt (measure_mono $ subset_univ s) $ by rw u₁ ; exact ennreal.lt_top_iff_ne_top.2 one_ne_top) end @[simp] lemma prob_empty : p ∅ = 0 := by rw [← coe_eq_coe, coe_eq_to_measure, measure_empty, coe_zero] @[simp] lemma prob_univ : p univ = 1 := by rw [← coe_eq_coe, coe_eq_to_measure]; exact p.measure_univ @[simp] lemma prob_mono {s t} (h : s ⊆ t) : p s ≤ p t := by rw [← coe_le_coe, coe_eq_to_measure, coe_eq_to_measure]; exact measure_mono h lemma prob_le_1 (a : set α): p a ≤ (1:nnreal) := begin intros, rewrite ← prob_univ p, apply prob_mono, apply subset_univ, end lemma prob_mono_null {s t} (h : t ⊆ s) (h₂ : p s = 0) : p t = 0 := by rw [← le_zero_iff_eq, ← h₂]; exact prob_mono p h lemma prob_Union_null {β} [encodable β] {s : β → set α} (h : ∀ i, p (s i) = 0) : p (⋃i, s i) = 0 := begin rw [← coe_eq_coe, coe_eq_to_measure, measure_Union_null, coe_zero], assume i, specialize h i, rwa [← coe_eq_coe, coe_eq_to_measure] at h end theorem prob_union_le (s₁ s₂ : set α) : p (s₁ ∪ s₂) ≤ p s₁ + p s₂ := by simp only [coe_le_coe.symm, coe_add, coe_eq_to_measure]; exact measure_union_le _ _ lemma prob_union {s₁ s₂ : set α} (hd : disjoint s₁ s₂) (h₁ : is_measurable s₁) (h₂ : is_measurable s₂) : p (s₁ ∪ s₂) = p s₁ + p s₂ := by simp only [coe_eq_coe.symm, coe_add, coe_eq_to_measure]; exact measure_union hd h₁ h₂ lemma prob_diff {s₁ s₂ : set α} (h : s₂ ⊆ s₁) (h₁ : is_measurable s₁) (h₂ : is_measurable s₂) : p (s₁ \ s₂) = p s₁ - p s₂ := by simp only [coe_eq_coe.symm, coe_sub, coe_eq_to_measure]; exact measure_diff h h₁ h₂ (to_measure_lt_top _ _) lemma prob_diff_inter {a b : set α} (h₁ : is_measurable a) (h₂ : is_measurable b) : p(b ∩ -a) + p(b ∩ a) = p(b) := begin have h :p(b) = p(b ∩ univ), by rewrite inter_univ b, rewrite [h,← compl_union_self a,set.inter_distrib_left,prob_union], have g : (b ∩ -a) ∩ (b ∩ a) = ∅, by rw [inter_left_comm,set.inter_assoc, compl_inter_self,inter_empty,inter_empty], apply disjoint_iff.2 g, { rewrite ← diff_eq, apply is_measurable.diff h₂ h₁, }, apply is_measurable.inter h₂ h₁, end lemma prob_union_inter (a b : set α) (g₁ : is_measurable a) (g₂ : is_measurable b) : p(a ∪ b) + p(a ∩ b) = p(a) + p(b) := begin have h₁ : a ∪ b = a ∪ (b ∩ -a),by rw [set.union_distrib_left, union_compl_self a,inter_univ], have h₂ : is_measurable(b ∩ -a), by exact is_measurable.diff g₂ g₁, have h₃ : a ∩ (b ∩ -a) = ∅, by tidy, rw h₁, rw [prob_union p (disjoint_iff.2 h₃) g₁ h₂], rw [←prob_diff_inter p g₁ g₂], simp, rw [inter_comm], end lemma prob_comp (a : set α) (h: is_measurable a) : p(-a) + p(a) = 1 := begin intros, rw ← prob_univ p, rw [←prob_union], simp, exact disjoint_iff.2 (@compl_inter_self _ a), apply is_measurable.compl h, assumption, end /-- The Bonnferroni inequality. -/ lemma prob_add_le_inter_add_one (a b : set α) (h_1 : is_measurable a) (h_2 : is_measurable b) : p(a) + p(b) ≤ p(a ∩ b) + 1 := begin rw [← prob_union_inter p a b h_1 h_2, ← add_comm], exact add_le_add_left' (prob_le_1 p (a ∪ b)), end protected lemma nonempty : nonempty α := classical.by_contradiction $ assume h, have 0 = p univ, by rw [univ_eq_empty_iff.2 h]; exact p.prob_empty.symm, @zero_ne_one nnreal _ $ by rwa [p.prob_univ] at this @[simp] lemma integral_const (r : ennreal) : integral p.to_measure (λa, r) = r := suffices integral p.to_measure (λa, ⨆ (h : a ∈ (univ : set α)), r) = r * p.to_measure univ, by rw [← coe_eq_to_measure] at this; simpa, @lintegral_supr_const α { μ := p.to_measure } r _ is_measurable.univ lemma integral_univ : integral p.to_measure (λ a, 1) = 1 := by simp -- somehow we need δ ≤ 1 o/w coercion hell. lemma neq_prob_set {α : Type} [measurable_space α] (f : α → nnreal) (μ : probability_measure α) (ε δ : nnreal) (hd : δ ≤ 1) (hS : is_measurable ({x : α | f x > ε})) : μ({x : α | f x > ε}) ≤ δ ↔ μ ({x : α | f x ≤ ε}) ≥ 1 - δ := begin rw nnreal.coe_le, have h₀ : {x : α | f x > ε} = - {x : α | f x ≤ ε},by tidy, have h₁ : - {x : α | f x > ε} = {x : α | f x ≤ ε}, by tidy, have h₃ : (μ ({x : α | f x > ε}) : ℝ) + μ{x : α | f x ≤ ε} = 1, { rw ←nnreal.coe_add, rw h₀, rw prob_comp, simp, rw ←h₁, apply is_measurable.compl hS, }, have h₅ : (μ ({x : α | f x > ε}) : ℝ) = 1 - μ ({x : α | f x ≤ ε}), { rw ←h₃, symmetry, rw add_sub_cancel, }, rw h₅, rw sub_le_iff_le_add', rw add_comm, rw ←sub_le_iff_le_add', rw ←nnreal.coe_one, rw ←nnreal.coe_sub _ _ hd, rw ←nnreal.coe_le, end lemma neq_prob_set' {α : Type} [measurable_space α] (f : α → nnreal) (μ : probability_measure α) (ε δ : nnreal) (hd : δ ≤ 1) (hS : is_measurable ({x : α | f x > ε})) : μ({x : α | f x > ε}) ≤ δ ↔ μ ({x : α | f x ≤ ε}) + δ ≥ 1 := begin have h₀ : {x : α | f x > ε} = - {x : α | f x ≤ ε},by tidy, have h₁ : - {x : α | f x > ε} = {x : α | f x ≤ ε}, by tidy, have h₃ : (μ ({x : α | f x > ε})) + μ{x : α | f x ≤ ε} = 1, { rw h₀, rw prob_comp, rw ←h₁, apply is_measurable.compl hS, }, symmetry, rw ← h₃, rw add_comm, rw ←add_le_add_iff_right, end lemma prob_trivial {α: Type} [measurable_space α]: ∀ P: α → Prop, ∀ μ: probability_measure α, (∀ x, P x) → μ {x: α | P x} = 1 := begin intros, have UNIV : {x: α | P x} = univ, { apply eq_univ_of_forall, intro, rw mem_set_of_eq, apply a, }, rw UNIV, apply prob_univ, end end end probability_measure section giry_monad variables {α : Type*} {β : Type*} {γ : Type*} variables [measurable_space α] [measurable_space β] [measurable_space γ] def pure (a : α) : probability_measure α := ⟨measure.dirac a, by rw [measure_theory.measure.dirac_apply a is_measurable.univ]; simp⟩ def map (f : α → β) (p : probability_measure α) : probability_measure β := if h : measurable f then ⟨measure.map f p, by rw [measure_theory.measure.map_apply h is_measurable.univ, preimage_univ]; exact p.measure_univ⟩ else pure (f $ classical.choice p.nonempty) def join (m : probability_measure (probability_measure α)) : probability_measure α := ⟨measure_theory.measure.bind m.to_measure probability_measure.to_measure, by rw [measure_theory.measure.bind_apply is_measurable.univ (measurable_to_measure α)]; simp [probability_measure.measure_univ]⟩ def bind (m : probability_measure α) (f : α → probability_measure β) : probability_measure β := join (map f m) def dirac (a : α) : probability_measure α := ⟨ measure.dirac a , by rw [dirac_apply _ is_measurable.univ]; simp ⟩ @[simp] theorem map_apply {f : α → β} (μ : probability_measure α) (hf : measurable f) {s : set β} (hs : is_measurable s) : (map f μ : probability_measure β) s = μ (f ⁻¹' s) := begin rw _root_.map, rw dif_pos hf, unfold_coes, congr, simp, apply measure_theory.measure.map_apply hf hs, end @[simp] lemma join_apply {m : probability_measure (probability_measure α)} : ∀{s : set α}, is_measurable s → (join m : probability_measure α) s = (integral m.to_measure (λμ, μ s)).to_nnreal := begin intros s hs, rw _root_.join, transitivity, unfold_coes, congr, simp, transitivity, refine measure_theory.measure.bind_apply hs (measurable_to_measure _), congr, funext, symmetry, transitivity, apply coe_to_nnreal, apply probability_measure.to_measure_ne_top, refl, end lemma prob.measurable_coe {s : set α} (hs : is_measurable s) : measurable (λμ : probability_measure α, μ s) := begin have h : (λ (μ : probability_measure α), μ s) = (λ μ:measure α, (μ s).to_nnreal) ∘ (λ μ:probability_measure α, μ.to_measure),by refl, rw h, refine measurable.comp _ (measurable_to_measure _), refine measurable.comp _ (measurable_coe hs), refine measurable_of_measurable_nnreal _, simp, exact measurable_id, end -- TODO(Kody) : Get rid of the tidy part at the end. (Makes it slow!) lemma prob.measurable_coe_iff_measurable_to_measure (f : β → probability_measure α) : measurable f ↔ measurable ((λ μ:probability_measure α, μ.to_measure) ∘ f ) := begin fsplit, {intro hf, exact measurable.comp (measurable_to_measure _) hf}, {intros hf s hs, refine measurable_space.comap_le_iff_le_map.1 _ _ _, exact measure.measurable_space.comap probability_measure.to_measure , simp, tidy,} end lemma prob.measurable_measure_kernel [measurable_space α] [measurable_space β] {f : α → probability_measure β} {A : set β} (hf : measurable f) (hA : is_measurable A) : measurable (λ a, f a A) := measurable.comp (prob.measurable_coe hA) hf -- Rethink and rename these. instance (β : Type u): measurable_space (set β) := ⊤ lemma prob_super [measurable_space α] [measurable_space β] {f: α → set β} (hf : measurable f) (μ : probability_measure β) : measurable (λ x, μ (f x)) := begin refine measurable.comp _ hf, intros i a, fsplit, end lemma measurable_to_nnreal : measurable (ennreal.to_nnreal) := measurable_of_measurable_nnreal measurable_id lemma measurable_to_nnreal_comp_of_measurable (f: α → ennreal) : (measurable f) → measurable (λ x, ennreal.to_nnreal (f x)) := assume h, measurable.comp measurable_to_nnreal h lemma measurable_of_ne_top (f : α → ennreal) (h : ∀ x, (f x) ≠ ⊤) (hf : measurable(λ x, ennreal.to_nnreal (f x))): measurable (λ x, f x) := begin have h₀ : ∀ x, ↑((f x).to_nnreal) = f x, assume x, rw coe_to_nnreal (h x), conv{congr,funext, rw ←h₀,}, apply measurable.comp measurable_coe hf, end lemma prob.measurable_of_measurable_coe (f : β → probability_measure α) (h : ∀(s : set α) (hs : is_measurable s), measurable (λb, f b s)) : measurable f := begin rw prob.measurable_coe_iff_measurable_to_measure, apply measurable_of_measurable_coe, intros s hs, conv{congr,funext,rw function.comp_apply,}, refine measurable_of_ne_top _ _ _, intro x, refine probability_measure.to_measure_ne_top _ _, exact h _ hs, end @[simp] lemma bind_apply {m : probability_measure α} {f : α → probability_measure β} {s : set β} (hs : is_measurable s) (hf : measurable f) : (bind m f : probability_measure β) s = (integral m.to_measure (λa, f a s)).to_nnreal := begin rw _root_.bind, rw _root_.join_apply hs, congr, have h : (_root_.map f m).to_measure = map f m.to_measure,{ apply measure.ext, intros s hs, rw measure_theory.measure.map_apply hf hs, rw _root_.map, rw dif_pos hf,unfold_coes, simp, apply measure_theory.measure.map_apply hf hs, }, rw h, rw integral_map _ hf, refine measurable.comp measurable_coe _, exact prob.measurable_coe hs, end attribute [irreducible] pure map join bind infixl ` >>=ₚ `:55 := _root_.bind infixl ` <$>ₚ `:55 := _root_.map notation `doₚ` binders ` ←ₚ ` m ` ; ` t:(scoped p, m >>=ₚ p) := t notation `retₚ` := _root_.dirac lemma ret_to_measure {γ : Type u} [measurable_space γ] : ∀ (x:γ), (retₚ x).to_measure = measure.dirac x := assume x, rfl def prod.prob_measure [measurable_space α][measurable_space β] (μ : probability_measure α) (ν : probability_measure β) : probability_measure (α × β) := doₚ x ←ₚ μ ; doₚ y ←ₚ ν ; retₚ (x, y) infixl ` ⊗ₚ `:55 := prod.prob_measure /- TODO(Kody) : 1) shorten these proofs by using the ones proven for measures. 2) Make a simp lemma to get rid of the conv block. -/ lemma prob_inl_measurable_dirac [measurable_space α][measurable_space β] : ∀ y : β, measurable (λ (x : α), retₚ (x, y)) := assume y, begin rw prob.measurable_coe_iff_measurable_to_measure, apply measurable_of_measurable_coe, intros s hs, conv{congr,funext,rw function.comp_apply, rw _root_.dirac,}, simp [hs,mem_prod_eq,lattice.supr_eq_if], apply measurable_const.if _ measurable_const, apply measurable.preimage _ hs, apply measurable.prod, dsimp, exact measurable_id, dsimp, exact measurable_const, end lemma prob_inr_measurable_dirac [measurable_space β][measurable_space α] : ∀ x : α, measurable (λ (y : β), retₚ (x, y)) := assume x, begin rw prob.measurable_coe_iff_measurable_to_measure, apply measurable_of_measurable_coe, intros s hs, conv{congr,funext,rw function.comp_apply, rw _root_.dirac,}, simp [hs,mem_prod_eq,lattice.supr_eq_if], apply measurable_const.if _ measurable_const, apply measurable.preimage _ hs, apply measurable.prod, dsimp, exact measurable_const, dsimp, exact measurable_id, end /- TODO(Kody): Duplication of proofs. Why do I need to manually `change` the goal? -/ @[simp] lemma prob.dirac_apply {A : set α} {B : set β} (hA : is_measurable A) (hB : is_measurable B) (a : α) (b : β) : (retₚ (a,b) : measure (α × β)) (A.prod B) = ((retₚ a : measure α) A) * ((retₚ b : measure β) B) := begin rw _root_.dirac, rw _root_.dirac,rw _root_.dirac, unfold_coes, simp, change ((( measure.dirac (a,b) : measure (α × β)) (A.prod B)) = (measure.dirac a : measure α) A * (measure.dirac b : measure β) B), rw [dirac_apply, dirac_apply, dirac_apply, mem_prod_eq], dsimp, by_cases Ha: (a ∈ A); by_cases Hb: (b ∈ B), repeat {simp [Ha, Hb]}, repeat {assumption}, exact is_measurable_set_prod hA hB, end @[simp] lemma prob.dirac_apply' {A : set α} {B : set β} (hA : is_measurable A) (hB : is_measurable B) (a : α) (b : β) : ((retₚ(a,b)).to_measure : measure (α × β)) (A.prod B) = (((retₚ a).to_measure : measure α) A) * (((retₚ b).to_measure : measure β) B) := begin rw _root_.dirac,rw _root_.dirac,rw _root_.dirac, unfold_coes, simp, change ((( measure.dirac (a,b) : measure (α × β)) (A.prod B)) = (measure.dirac a : measure α) A * (measure.dirac b : measure β) B), rw [dirac_apply, dirac_apply, dirac_apply, mem_prod_eq], dsimp, by_cases Ha: (a ∈ A); by_cases Hb: (b ∈ B), repeat {simp [Ha, Hb]}, repeat {assumption}, exact is_measurable_set_prod hA hB, end end giry_monad section cond_prob noncomputable def cond_prob {α : Type*} [measurable_space α] (p : probability_measure α) (a b : set α) := p(a ∩ b)/p(b) notation `ℙ^`:95 p `[[`:95 a ` | `:95 b `]]`:0 := cond_prob p a b parameters {α : Type*} [measurable_space α] (p : probability_measure α) lemma cond_prob_rw (a b : set α) (h₁ : p(b) ≠ 0): p(a ∩ b) = ℙ^p [[ a | b ]] * p(b) := begin unfold cond_prob, rw [nnreal.div_def,mul_assoc], have g₁ : (1 : ennreal) < ⊤, { rw lattice.lt_top_iff_ne_top, apply ennreal.one_ne_top, }, have g₂ : ∀ a, (p(a) ≠ 0) → (p(a))⁻¹ * p(a) = 1, { intros a k, rw mul_comm, apply nnreal.mul_inv_cancel, exact k, }, rw g₂ b h₁, simp, end /-- Bayes theorem for two sets. -/ theorem cond_prob_swap {a b : set α} (h₁ : p a ≠ 0) (h₂ : p b ≠ 0) : ℙ^p [[ b | a ]] * p(a) = ℙ^p [[ a | b ]] * p(b) := begin unfold cond_prob, rw [nnreal.div_def,mul_assoc], have g₁ : (1 : ennreal) < ⊤, { rw lattice.lt_top_iff_ne_top, apply ennreal.one_ne_top, }, have g₂ : ∀ a, (p(a) ≠ 0) → (p(a))⁻¹ * p(a) = 1, { intros a k, rw mul_comm, apply nnreal.mul_inv_cancel, exact k, }, rw [g₂ a,nnreal.div_def,mul_assoc,g₂ b, mul_one], symmetry, rw [mul_one,set.inter_comm], assumption, assumption, end end cond_prob section giry_prod end giry_prod
3244cfaa370a1844c565d3e63e1133145c948973
4727251e0cd73359b15b664c3170e5d754078599
/src/analysis/complex/schwarz.lean
ae1002ae85c86d547461fde7e467b8bf84de2a35
[ "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
8,216
lean
/- Copyright (c) 2022 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import analysis.complex.abs_max import analysis.complex.removable_singularity /-! # Schwarz lemma In this file we prove several versions of the Schwarz lemma. * `complex.norm_deriv_le_div_of_maps_to_ball`, `complex.abs_deriv_le_div_of_maps_to_ball`: if `f : ℂ → E` sends an open disk with center `c` and a positive radius `R₁` to an open ball with center `f c` and radius `R₂`, then the absolute value of the derivative of `f` at `c` is at most the ratio `R₂ / R₁`; * `complex.dist_le_div_mul_dist_of_maps_to_ball`: if `f : ℂ → E` sends an open disk with center `c` and radius `R₁` to an open disk with center `f c` and radius `R₂`, then for any `z` in the former disk we have `dist (f z) (f c) ≤ (R₂ / R₁) * dist z c`; * `complex.abs_deriv_le_one_of_maps_to_ball`: if `f : ℂ → ℂ` sends an open disk of positive radius to itself and the center of this disk to itself, then the absolute value of the derivative of `f` at the center of this disk is at most `1`; * `complex.dist_le_dist_of_maps_to_ball`: if `f : ℂ → ℂ` sends an open disk to itself and the center `c` of this disk to itself, then for any point `z` of this disk we have `dist (f z) c ≤ dist z c`; * `complex.abs_le_abs_of_maps_to_ball`: if `f : ℂ → ℂ` sends an open disk with center `0` to itself, then for any point `z` of this disk we have `abs (f z) ≤ abs z`. ## Implementation notes We prove some versions of the Schwarz lemma for a map `f : ℂ → E` taking values in any normed space over complex numbers. ## TODO * Prove that these inequalities are strict unless `f` is an affine map. * Prove that any diffeomorphism of the unit disk to itself is a Möbius map. ## Tags Schwarz lemma -/ open metric set function filter topological_space open_locale topological_space namespace complex section space variables {E : Type*} [normed_group E] [normed_space ℂ E] {R R₁ R₂ : ℝ} {f : ℂ → E} {c z : ℂ} /-- An auxiliary lemma for `complex.norm_dslope_le_div_of_maps_to_ball`. -/ lemma schwarz_aux {f : ℂ → ℂ} (hd : differentiable_on ℂ f (ball c R₁)) (h_maps : maps_to f (ball c R₁) (ball (f c) R₂)) (hz : z ∈ ball c R₁) : ∥dslope f c z∥ ≤ R₂ / R₁ := begin have hR₁ : 0 < R₁, from nonempty_ball.1 ⟨z, hz⟩, suffices : ∀ᶠ r in 𝓝[<] R₁, ∥dslope f c z∥ ≤ R₂ / r, { refine ge_of_tendsto _ this, exact (tendsto_const_nhds.div tendsto_id hR₁.ne').mono_left nhds_within_le_nhds }, rw mem_ball at hz, filter_upwards [Ioo_mem_nhds_within_Iio ⟨hz, le_rfl⟩] with r hr, have hr₀ : 0 < r, from dist_nonneg.trans_lt hr.1, replace hd : diff_cont_on_cl ℂ (dslope f c) (ball c r), { refine differentiable_on.diff_cont_on_cl _, rw closure_ball c hr₀.ne', exact ((differentiable_on_dslope $ ball_mem_nhds _ hR₁).mpr hd).mono (closed_ball_subset_ball hr.2) }, refine norm_le_of_forall_mem_frontier_norm_le bounded_ball hd _ _, { rw frontier_ball c hr₀.ne', intros z hz, have hz' : z ≠ c, from ne_of_mem_sphere hz hr₀.ne', rw [dslope_of_ne _ hz', slope_def_module, norm_smul, norm_inv, (mem_sphere_iff_norm _ _ _).1 hz, ← div_eq_inv_mul, div_le_div_right hr₀, ← dist_eq_norm], exact le_of_lt (h_maps (mem_ball.2 (by { rw mem_sphere.1 hz, exact hr.2 }))) }, { rw [closure_ball c hr₀.ne', mem_closed_ball], exact hr.1.le } end /-- Two cases of the **Schwarz Lemma** (derivative and distance), merged together. -/ lemma norm_dslope_le_div_of_maps_to_ball (hd : differentiable_on ℂ f (ball c R₁)) (h_maps : maps_to f (ball c R₁) (ball (f c) R₂)) (hz : z ∈ ball c R₁) : ∥dslope f c z∥ ≤ R₂ / R₁ := begin have hR₁ : 0 < R₁, from nonempty_ball.1 ⟨z, hz⟩, have hR₂ : 0 < R₂, from nonempty_ball.1 ⟨f z, h_maps hz⟩, cases eq_or_ne (dslope f c z) 0 with hc hc, { rw [hc, norm_zero], exact div_nonneg hR₂.le hR₁.le }, rcases exists_dual_vector ℂ _ hc with ⟨g, hg, hgf⟩, have hg' : ∥g∥₊ = 1, from nnreal.eq hg, have hg₀ : ∥g∥₊ ≠ 0, by simpa only [hg'] using one_ne_zero, calc ∥dslope f c z∥ = ∥dslope (g ∘ f) c z∥ : begin rw [g.dslope_comp, hgf, is_R_or_C.norm_of_real, norm_norm], exact λ _, hd.differentiable_at (ball_mem_nhds _ hR₁) end ... ≤ R₂ / R₁ : begin refine schwarz_aux (g.differentiable.comp_differentiable_on hd) (maps_to.comp _ h_maps) hz, simpa only [hg', nnreal.coe_one, one_mul] using g.lipschitz.maps_to_ball hg₀ (f c) R₂ end end /-- The **Schwarz Lemma**: if `f : ℂ → E` sends an open disk with center `c` and a positive radius `R₁` to an open ball with center `f c` and radius `R₂`, then the absolute value of the derivative of `f` at `c` is at most the ratio `R₂ / R₁`. -/ lemma norm_deriv_le_div_of_maps_to_ball (hd : differentiable_on ℂ f (ball c R₁)) (h_maps : maps_to f (ball c R₁) (ball (f c) R₂)) (h₀ : 0 < R₁) : ∥deriv f c∥ ≤ R₂ / R₁ := by simpa only [dslope_same] using norm_dslope_le_div_of_maps_to_ball hd h_maps (mem_ball_self h₀) /-- The **Schwarz Lemma**: if `f : ℂ → E` sends an open disk with center `c` and radius `R₁` to an open ball with center `f c` and radius `R₂`, then for any `z` in the former disk we have `dist (f z) (f c) ≤ (R₂ / R₁) * dist z c`. -/ lemma dist_le_div_mul_dist_of_maps_to_ball (hd : differentiable_on ℂ f (ball c R₁)) (h_maps : maps_to f (ball c R₁) (ball (f c) R₂)) (hz : z ∈ ball c R₁) : dist (f z) (f c) ≤ (R₂ / R₁) * dist z c := begin rcases eq_or_ne z c with rfl|hne, { simp only [dist_self, mul_zero] }, simpa only [dslope_of_ne _ hne, slope_def_module, norm_smul, norm_inv, ← div_eq_inv_mul, ← dist_eq_norm, div_le_iff (dist_pos.2 hne)] using norm_dslope_le_div_of_maps_to_ball hd h_maps hz end end space variables {f : ℂ → ℂ} {c z : ℂ} {R R₁ R₂ : ℝ} /-- The **Schwarz Lemma**: if `f : ℂ → ℂ` sends an open disk with center `c` and a positive radius `R₁` to an open disk with center `f c` and radius `R₂`, then the absolute value of the derivative of `f` at `c` is at most the ratio `R₂ / R₁`. -/ lemma abs_deriv_le_div_of_maps_to_ball (hd : differentiable_on ℂ f (ball c R₁)) (h_maps : maps_to f (ball c R₁) (ball (f c) R₂)) (h₀ : 0 < R₁) : abs (deriv f c) ≤ R₂ / R₁ := norm_deriv_le_div_of_maps_to_ball hd h_maps h₀ /-- The **Schwarz Lemma**: if `f : ℂ → ℂ` sends an open disk of positive radius to itself and the center of this disk to itself, then the absolute value of the derivative of `f` at the center of this disk is at most `1`. -/ lemma abs_deriv_le_one_of_maps_to_ball (hd : differentiable_on ℂ f (ball c R)) (h_maps : maps_to f (ball c R) (ball c R)) (hc : f c = c) (h₀ : 0 < R) : abs (deriv f c) ≤ 1 := (norm_deriv_le_div_of_maps_to_ball hd (by rwa hc) h₀).trans_eq (div_self h₀.ne') /-- The **Schwarz Lemma**: if `f : ℂ → ℂ` sends an open disk to itself and the center `c` of this disk to itself, then for any point `z` of this disk we have `dist (f z) c ≤ dist z c`. -/ lemma dist_le_dist_of_maps_to_ball_self (hd : differentiable_on ℂ f (ball c R)) (h_maps : maps_to f (ball c R) (ball c R)) (hc : f c = c) (hz : z ∈ ball c R) : dist (f z) c ≤ dist z c := have hR : 0 < R, from nonempty_ball.1 ⟨z, hz⟩, by simpa only [hc, div_self hR.ne', one_mul] using dist_le_div_mul_dist_of_maps_to_ball hd (by rwa hc) hz /-- The **Schwarz Lemma**: if `f : ℂ → ℂ` sends an open disk with center `0` to itself, the for any point `z` of this disk we have `abs (f z) ≤ abs z`. -/ lemma abs_le_abs_of_maps_to_ball_self (hd : differentiable_on ℂ f (ball 0 R)) (h_maps : maps_to f (ball 0 R) (ball 0 R)) (h₀ : f 0 = 0) (hz : abs z < R) : abs (f z) ≤ abs z := begin replace hz : z ∈ ball (0 : ℂ) R, from mem_ball_zero_iff.2 hz, simpa only [dist_zero_right] using dist_le_dist_of_maps_to_ball_self hd h_maps h₀ hz end end complex
d1cdba628b68a54c02830721abc98219032d3447
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
/src/linear_algebra/matrix/adjugate.lean
70f25b301bc6e1ccfbb7be229e204ca0f5f7fdfd
[ "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
18,369
lean
/- Copyright (c) 2019 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import algebra.associated import algebra.regular.basic import data.matrix.notation import linear_algebra.matrix.polynomial import linear_algebra.matrix.mv_polynomial import tactic.linarith import tactic.ring_exp import ring_theory.polynomial.basic /-! # Cramer's rule and adjugate matrices The adjugate matrix is the transpose of the cofactor matrix. It is calculated with Cramer's rule, which we introduce first. The vectors returned by Cramer's rule are given by the linear map `cramer`, which sends a matrix `A` and vector `b` to the vector consisting of the determinant of replacing the `i`th column of `A` with `b` at index `i` (written as `(A.update_column i b).det`). Using Cramer's rule, we can compute for each matrix `A` the matrix `adjugate A`. The entries of the adjugate are the determinants of each minor of `A`. Instead of defining a minor to be `A` with row `i` and column `j` deleted, we replace the `i`th row of `A` with the `j`th basis vector; this has the same determinant as the minor but more importantly equals Cramer's rule applied to `A` and the `j`th basis vector, simplifying the subsequent proofs. We prove the adjugate behaves like `det A • A⁻¹`. ## Main definitions * `matrix.cramer A b`: the vector output by Cramer's rule on `A` and `b`. * `matrix.adjugate A`: the adjugate (or classical adjoint) of the matrix `A`. ## References * https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix ## Tags cramer, cramer's rule, adjugate -/ namespace matrix universes u v variables {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α] open_locale matrix big_operators open equiv equiv.perm finset section cramer /-! ### `cramer` section Introduce the linear map `cramer` with values defined by `cramer_map`. After defining `cramer_map` and showing it is linear, we will restrict our proofs to using `cramer`. -/ variables (A : matrix n n α) (b : n → α) /-- `cramer_map A b i` is the determinant of the matrix `A` with column `i` replaced with `b`, and thus `cramer_map A b` is the vector output by Cramer's rule on `A` and `b`. If `A ⬝ x = b` has a unique solution in `x`, `cramer_map A` sends the vector `b` to `A.det • x`. Otherwise, the outcome of `cramer_map` is well-defined but not necessarily useful. -/ def cramer_map (i : n) : α := (A.update_column i b).det lemma cramer_map_is_linear (i : n) : is_linear_map α (λ b, cramer_map A b i) := { map_add := det_update_column_add _ _, map_smul := det_update_column_smul _ _ } lemma cramer_is_linear : is_linear_map α (cramer_map A) := begin split; intros; ext i, { apply (cramer_map_is_linear A i).1 }, { apply (cramer_map_is_linear A i).2 } end /-- `cramer A b i` is the determinant of the matrix `A` with column `i` replaced with `b`, and thus `cramer A b` is the vector output by Cramer's rule on `A` and `b`. If `A ⬝ x = b` has a unique solution in `x`, `cramer A` sends the vector `b` to `A.det • x`. Otherwise, the outcome of `cramer` is well-defined but not necessarily useful. -/ def cramer (A : matrix n n α) : (n → α) →ₗ[α] (n → α) := is_linear_map.mk' (cramer_map A) (cramer_is_linear A) lemma cramer_apply (i : n) : cramer A b i = (A.update_column i b).det := rfl lemma cramer_transpose_row_self (i : n) : Aᵀ.cramer (A i) = pi.single i A.det := begin ext j, rw [cramer_apply, pi.single_apply], split_ifs with h, { -- i = j: this entry should be `A.det` subst h, simp only [update_column_transpose, det_transpose, update_row, function.update_eq_self] }, { -- i ≠ j: this entry should be 0 rw [update_column_transpose, det_transpose], apply det_zero_of_row_eq h, rw [update_row_self, update_row_ne (ne.symm h)] } end lemma cramer_row_self (i : n) (h : ∀ j, b j = A j i) : A.cramer b = pi.single i A.det := begin rw [← transpose_transpose A, det_transpose], convert cramer_transpose_row_self Aᵀ i, exact funext h end @[simp] lemma cramer_one : cramer (1 : matrix n n α) = 1 := begin ext i j, convert congr_fun (cramer_row_self (1 : matrix n n α) (pi.single i 1) i _) j, { simp }, { intros j, rw [matrix.one_eq_pi_single, pi.single_comm] } end lemma cramer_smul (r : α) (A : matrix n n α) : cramer (r • A) = r ^ (fintype.card n - 1) • cramer A := linear_map.ext $ λ b, funext $ λ _, det_update_column_smul' _ _ _ _ @[simp] lemma cramer_subsingleton_apply [subsingleton n] (A : matrix n n α) (b : n → α) (i : n) : cramer A b i = b i := by rw [cramer_apply, det_eq_elem_of_subsingleton _ i, update_column_self] lemma cramer_zero [nontrivial n] : cramer (0 : matrix n n α) = 0 := begin ext i j, obtain ⟨j', hj'⟩ : ∃ j', j' ≠ j := exists_ne j, apply det_eq_zero_of_column_eq_zero j', intro j'', simp [update_column_ne hj'], end /-- Use linearity of `cramer` to take it out of a summation. -/ lemma sum_cramer {β} (s : finset β) (f : β → n → α) : ∑ x in s, cramer A (f x) = cramer A (∑ x in s, f x) := (linear_map.map_sum (cramer A)).symm /-- Use linearity of `cramer` and vector evaluation to take `cramer A _ i` out of a summation. -/ lemma sum_cramer_apply {β} (s : finset β) (f : n → β → α) (i : n) : ∑ x in s, cramer A (λ j, f j x) i = cramer A (λ (j : n), ∑ x in s, f j x) i := calc ∑ x in s, cramer A (λ j, f j x) i = (∑ x in s, cramer A (λ j, f j x)) i : (finset.sum_apply i s _).symm ... = cramer A (λ (j : n), ∑ x in s, f j x) i : by { rw [sum_cramer, cramer_apply], congr' with j, apply finset.sum_apply } end cramer section adjugate /-! ### `adjugate` section Define the `adjugate` matrix and a few equations. These will hold for any matrix over a commutative ring. -/ /-- The adjugate matrix is the transpose of the cofactor matrix. Typically, the cofactor matrix is defined by taking the determinant of minors, i.e. the matrix with a row and column removed. However, the proof of `mul_adjugate` becomes a lot easier if we define the minor as replacing a column with a basis vector, since it allows us to use facts about the `cramer` map. -/ def adjugate (A : matrix n n α) : matrix n n α := λ i, cramer Aᵀ (pi.single i 1) lemma adjugate_def (A : matrix n n α) : adjugate A = λ i, cramer Aᵀ (pi.single i 1) := rfl lemma adjugate_apply (A : matrix n n α) (i j : n) : adjugate A i j = (A.update_row j (pi.single i 1)).det := by { rw adjugate_def, simp only, rw [cramer_apply, update_column_transpose, det_transpose], } lemma adjugate_transpose (A : matrix n n α) : (adjugate A)ᵀ = adjugate (Aᵀ) := begin ext i j, rw [transpose_apply, adjugate_apply, adjugate_apply, update_row_transpose, det_transpose], rw [det_apply', det_apply'], apply finset.sum_congr rfl, intros σ _, congr' 1, by_cases i = σ j, { -- Everything except `(i , j)` (= `(σ j , j)`) is given by A, and the rest is a single `1`. congr; ext j', subst h, have : σ j' = σ j ↔ j' = j := σ.injective.eq_iff, rw [update_row_apply, update_column_apply], simp_rw this, rw [←dite_eq_ite, ←dite_eq_ite], congr' 1 with rfl, rw [pi.single_eq_same, pi.single_eq_same], }, { -- Otherwise, we need to show that there is a `0` somewhere in the product. have : (∏ j' : n, update_column A j (pi.single i 1) (σ j') j') = 0, { apply prod_eq_zero (mem_univ j), rw [update_column_self, pi.single_eq_of_ne' h], }, rw this, apply prod_eq_zero (mem_univ (σ⁻¹ i)), erw [apply_symm_apply σ i, update_row_self], apply pi.single_eq_of_ne, intro h', exact h ((symm_apply_eq σ).mp h') } end /-- Since the map `b ↦ cramer A b` is linear in `b`, it must be multiplication by some matrix. This matrix is `A.adjugate`. -/ lemma cramer_eq_adjugate_mul_vec (A : matrix n n α) (b : n → α) : cramer A b = A.adjugate.mul_vec b := begin nth_rewrite 1 ← A.transpose_transpose, rw [← adjugate_transpose, adjugate_def], have : b = ∑ i, (b i) • (pi.single i 1), { refine (pi_eq_sum_univ b).trans _, congr' with j, simp [pi.single_apply, eq_comm], congr, }, nth_rewrite 0 this, ext k, simp [mul_vec, dot_product, mul_comm], end lemma mul_adjugate_apply (A : matrix n n α) (i j k) : A i k * adjugate A k j = cramer Aᵀ (pi.single k (A i k)) j := begin erw [←smul_eq_mul, ←pi.smul_apply, ←linear_map.map_smul, ←pi.single_smul', smul_eq_mul, mul_one], end lemma mul_adjugate (A : matrix n n α) : A ⬝ adjugate A = A.det • 1 := begin ext i j, rw [mul_apply, pi.smul_apply, pi.smul_apply, one_apply, smul_eq_mul, mul_boole], simp [mul_adjugate_apply, sum_cramer_apply, cramer_transpose_row_self, pi.single_apply, eq_comm] end lemma adjugate_mul (A : matrix n n α) : adjugate A ⬝ A = A.det • 1 := calc adjugate A ⬝ A = (Aᵀ ⬝ (adjugate Aᵀ))ᵀ : by rw [←adjugate_transpose, ←transpose_mul, transpose_transpose] ... = A.det • 1 : by rw [mul_adjugate (Aᵀ), det_transpose, transpose_smul, transpose_one] lemma adjugate_smul (r : α) (A : matrix n n α) : adjugate (r • A) = r ^ (fintype.card n - 1) • adjugate A := begin rw [adjugate, adjugate, transpose_smul, cramer_smul], refl, end /-- A stronger form of **Cramer's rule** that allows us to solve some instances of `A ⬝ x = b` even if the determinant is not a unit. A sufficient (but still not necessary) condition is that `A.det` divides `b`. -/ @[simp] lemma mul_vec_cramer (A : matrix n n α) (b : n → α) : A.mul_vec (cramer A b) = A.det • b := by rw [cramer_eq_adjugate_mul_vec, mul_vec_mul_vec, mul_adjugate, smul_mul_vec_assoc, one_mul_vec] lemma adjugate_subsingleton [subsingleton n] (A : matrix n n α) : adjugate A = 1 := begin ext i j, simp [subsingleton.elim i j, adjugate_apply, det_eq_elem_of_subsingleton _ i] end lemma adjugate_eq_one_of_card_eq_one {A : matrix n n α} (h : fintype.card n = 1) : adjugate A = 1 := begin haveI : subsingleton n := fintype.card_le_one_iff_subsingleton.mp h.le, exact adjugate_subsingleton _ end @[simp] lemma adjugate_zero [nontrivial n] : adjugate (0 : matrix n n α) = 0 := begin ext i j, obtain ⟨j', hj'⟩ : ∃ j', j' ≠ j := exists_ne j, apply det_eq_zero_of_column_eq_zero j', intro j'', simp [update_column_ne hj'], end @[simp] lemma adjugate_one : adjugate (1 : matrix n n α) = 1 := by { ext, simp [adjugate_def, matrix.one_apply, pi.single_apply, eq_comm] } lemma _root_.ring_hom.map_adjugate {R S : Type*} [comm_ring R] [comm_ring S] (f : R →+* S) (M : matrix n n R) : f.map_matrix M.adjugate = matrix.adjugate (f.map_matrix M) := begin ext i k, have : pi.single i (1 : S) = f ∘ pi.single i 1, { rw ←f.map_one, exact pi.single_op (λ i, f) (λ i, f.map_zero) i (1 : R) }, rw [adjugate_apply, ring_hom.map_matrix_apply, map_apply, ring_hom.map_matrix_apply, this, ←map_update_row, ←ring_hom.map_matrix_apply, ←ring_hom.map_det, ←adjugate_apply] end lemma _root_.alg_hom.map_adjugate {R A B : Type*} [comm_semiring R] [comm_ring A] [comm_ring B] [algebra R A] [algebra R B] (f : A →ₐ[R] B) (M : matrix n n A) : f.map_matrix M.adjugate = matrix.adjugate (f.map_matrix M) := f.to_ring_hom.map_adjugate _ lemma det_adjugate (A : matrix n n α) : (adjugate A).det = A.det ^ (fintype.card n - 1) := begin -- get rid of the `- 1` cases (fintype.card n).eq_zero_or_pos with h_card h_card, { haveI : is_empty n := fintype.card_eq_zero_iff.mp h_card, rw [h_card, nat.zero_sub, pow_zero, adjugate_subsingleton, det_one] }, replace h_card := tsub_add_cancel_of_le h_card.nat_succ_le, -- express `A` as an evaluation of a polynomial in n^2 variables, and solve in the polynomial ring -- where `A'.det` is non-zero. let A' := mv_polynomial_X n n ℤ, suffices : A'.adjugate.det = A'.det ^ (fintype.card n - 1), { rw [←mv_polynomial_X_map_matrix_aeval ℤ A, ←alg_hom.map_adjugate, ←alg_hom.map_det, ←alg_hom.map_det, ←alg_hom.map_pow, this] }, apply mul_left_cancel₀ (show A'.det ≠ 0, from det_mv_polynomial_X_ne_zero n ℤ), calc A'.det * A'.adjugate.det = (A' ⬝ adjugate A').det : (det_mul _ _).symm ... = A'.det ^ fintype.card n : by rw [mul_adjugate, det_smul, det_one, mul_one] ... = A'.det * A'.det ^ (fintype.card n - 1) : by rw [←pow_succ, h_card], end @[simp] lemma adjugate_fin_zero (A : matrix (fin 0) (fin 0) α) : adjugate A = 0 := @subsingleton.elim _ matrix.subsingleton_of_empty_left _ _ @[simp] lemma adjugate_fin_one (A : matrix (fin 1) (fin 1) α) : adjugate A = 1 := adjugate_subsingleton A lemma adjugate_fin_two (A : matrix (fin 2) (fin 2) α) : adjugate A = ![![A 1 1, -A 0 1], ![-A 1 0, A 0 0]] := begin ext i j, rw [adjugate_apply, det_fin_two], fin_cases i with [0, 1]; fin_cases j with [0, 1]; simp only [nat.one_ne_zero, one_mul, fin.one_eq_zero_iff, pi.single_eq_same, zero_mul, fin.zero_eq_one_iff, sub_zero, pi.single_eq_of_ne, ne.def, not_false_iff, update_row_self, update_row_ne, cons_val_zero, mul_zero, mul_one, zero_sub, cons_val_one, head_cons], end @[simp] lemma adjugate_fin_two' (a b c d : α) : adjugate ![![a, b], ![c, d]] = ![![d, -b], ![-c, a]] := adjugate_fin_two _ lemma adjugate_conj_transpose [star_ring α] (A : matrix n n α) : A.adjugateᴴ = adjugate (Aᴴ) := begin dsimp only [conj_transpose], have : Aᵀ.adjugate.map star = adjugate (Aᵀ.map star) := ((star_ring_aut : α ≃+* α).to_ring_hom.map_adjugate Aᵀ), rw [A.adjugate_transpose, this], end lemma is_regular_of_is_left_regular_det {A : matrix n n α} (hA : is_left_regular A.det) : is_regular A := begin split, { intros B C h, refine hA.matrix _, rw [←matrix.one_mul B, ←matrix.one_mul C, ←matrix.smul_mul, ←matrix.smul_mul, ←adjugate_mul, matrix.mul_assoc, matrix.mul_assoc, ←mul_eq_mul A, h, mul_eq_mul] }, { intros B C h, simp only [mul_eq_mul] at h, refine hA.matrix _, rw [←matrix.mul_one B, ←matrix.mul_one C, ←matrix.mul_smul, ←matrix.mul_smul, ←mul_adjugate, ←matrix.mul_assoc, ←matrix.mul_assoc, h] } end lemma adjugate_mul_distrib_aux (A B : matrix n n α) (hA : is_left_regular A.det) (hB : is_left_regular B.det) : adjugate (A ⬝ B) = adjugate B ⬝ adjugate A := begin have hAB : is_left_regular (A ⬝ B).det, { rw [det_mul], exact hA.mul hB }, refine (is_regular_of_is_left_regular_det hAB).left _, rw [mul_eq_mul, mul_adjugate, mul_eq_mul, matrix.mul_assoc, ←matrix.mul_assoc B, mul_adjugate, smul_mul, matrix.one_mul, mul_smul, mul_adjugate, smul_smul, mul_comm, ←det_mul] end /-- Proof follows from "The trace Cayley-Hamilton theorem" by Darij Grinberg, Section 5.3 -/ lemma adjugate_mul_distrib (A B : matrix n n α) : adjugate (A ⬝ B) = adjugate B ⬝ adjugate A := begin casesI subsingleton_or_nontrivial α, { simp }, let g : matrix n n α → matrix n n (polynomial α) := λ M, M.map polynomial.C + (polynomial.X : polynomial α) • 1, let f' : matrix n n (polynomial α) →+* matrix n n α := (polynomial.eval_ring_hom 0).map_matrix, have f'_inv : ∀ M, f' (g M) = M, { intro, ext, simp [f', g], }, have f'_adj : ∀ (M : matrix n n α), f' (adjugate (g M)) = adjugate M, { intro, rw [ring_hom.map_adjugate, f'_inv] }, have f'_g_mul : ∀ (M N : matrix n n α), f' (g M ⬝ g N) = M ⬝ N, { intros, rw [←mul_eq_mul, ring_hom.map_mul, f'_inv, f'_inv, mul_eq_mul] }, have hu : ∀ (M : matrix n n α), is_regular (g M).det, { intros M, refine polynomial.monic.is_regular _, simp only [g, polynomial.monic.def, ←polynomial.leading_coeff_det_X_one_add_C M, add_comm] }, rw [←f'_adj, ←f'_adj, ←f'_adj, ←mul_eq_mul (f' (adjugate (g B))), ←f'.map_mul, mul_eq_mul, ←adjugate_mul_distrib_aux _ _ (hu A).left (hu B).left, ring_hom.map_adjugate, ring_hom.map_adjugate, f'_inv, f'_g_mul] end @[simp] lemma adjugate_pow (A : matrix n n α) (k : ℕ) : adjugate (A ^ k) = (adjugate A) ^ k := begin induction k with k IH, { simp }, { rw [pow_succ', mul_eq_mul, adjugate_mul_distrib, IH, ←mul_eq_mul, pow_succ] } end lemma det_smul_adjugate_adjugate (A : matrix n n α) : det A • adjugate (adjugate A) = det A ^ (fintype.card n - 1) • A := begin have : A ⬝ (A.adjugate ⬝ A.adjugate.adjugate) = A ⬝ (A.det ^ (fintype.card n - 1) • 1), { rw [←adjugate_mul_distrib, adjugate_mul, adjugate_smul, adjugate_one], }, rwa [←matrix.mul_assoc, mul_adjugate, matrix.mul_smul, matrix.mul_one, matrix.smul_mul, matrix.one_mul] at this, end /-- Note that this is not true for `fintype.card n = 1` since `1 - 2 = 0` and not `-1`. -/ lemma adjugate_adjugate (A : matrix n n α) (h : fintype.card n ≠ 1) : adjugate (adjugate A) = det A ^ (fintype.card n - 2) • A := begin -- get rid of the `- 2` cases h_card : (fintype.card n) with n', { haveI : is_empty n := fintype.card_eq_zero_iff.mp h_card, exact @subsingleton.elim _ (matrix.subsingleton_of_empty_left) _ _, }, cases n', { exact (h h_card).elim }, rw ←h_card, -- express `A` as an evaluation of a polynomial in n^2 variables, and solve in the polynomial ring -- where `A'.det` is non-zero. let A' := mv_polynomial_X n n ℤ, suffices : adjugate (adjugate A') = det A' ^ (fintype.card n - 2) • A', { rw [←mv_polynomial_X_map_matrix_aeval ℤ A, ←alg_hom.map_adjugate, ←alg_hom.map_adjugate, this, ←alg_hom.map_det, ← alg_hom.map_pow], -- TODO: missing an `alg_hom.map_smul_of_tower` here. ext i j, dsimp [-mv_polynomial_X], rw [←alg_hom.map_mul] }, have h_card' : fintype.card n - 2 + 1 = fintype.card n - 1, { simp [h_card] }, have is_reg : is_smul_regular (mv_polynomial (n × n) ℤ) (det A') := λ x y, mul_left_cancel₀ (det_mv_polynomial_X_ne_zero n ℤ), apply is_reg.matrix, rw [smul_smul, ←pow_succ, h_card', det_smul_adjugate_adjugate], end /-- A weaker version of `matrix.adjugate_adjugate` that uses `nontrivial`. -/ lemma adjugate_adjugate' (A : matrix n n α) [nontrivial n] : adjugate (adjugate A) = det A ^ (fintype.card n - 2) • A := adjugate_adjugate _ $ fintype.one_lt_card.ne' end adjugate end matrix
090b2cc4e9a716c032f97a54665e6634e7f29f74
f68c8823d8ddc719de8a4513815174aa7408ac4a
/lean_resolutions/PUZ130_1.lean
9535848764f080a0d1e968aa2538af6f073cc825
[]
no_license
FredsoNerd/tptp-lean-puzzles
e7ea66a0de9aa3cb7cc7480299f01adf885440a6
43d4d77524e797a4ac7a62b2cfaf8df08b409815
refs/heads/master
1,606,359,611,765
1,576,824,274,000
1,576,824,274,000
228,945,807
4
0
null
null
null
null
UTF-8
Lean
false
false
1,898
lean
-------------------------------------------------------------------------------- -- File : PUZ130_1 : TPTP v7.3.0. Released v5.5.0. -- Domain : Puzzles -- Problem : Garfield and Odie -- Version : Especial. -- English : Garfield is a cat and Odie is a dog. Cats and dogs are pets. Jon -- is a human. Every pet has a human owner. Jon owns Garfield and -- Odie, and they are the only cat and dog he owns. If a dog chases -- a cat, then the cat's owner hates the dog's owner. Odie has chased -- Garfield. Therefore, Jon hates himself. -- Source : [TPTP : tptp.org] -------------------------------------------------------------------------------- variable animal : Type variable cat : Type variable dog : Type variable human: Type variable cat_to_animal: cat → animal variable dog_to_animal: dog → animal variable garfield : cat variable odie : dog variable jon: human variable owner_of : animal → human variable chased : dog → cat → Prop variable hates : human → human → Prop -- axioms (as variables too) variable human_owner : ∀ A : animal, ∃ H : human, H = owner_of(A) variable jon_owns_garfield : jon = owner_of(cat_to_animal garfield) variable jon_owns_odie : jon = owner_of(dog_to_animal odie) variable jon_owns_only : ∀ A : animal, jon = owner_of(A) → A = cat_to_animal(garfield) ∨ A = dog_to_animal(odie) variable dog_chase_cat : ∀ (C : cat) (D : dog), chased D C → hates (owner_of(cat_to_animal(C))) (owner_of(dog_to_animal(D))) variable odie_chased_garfield : chased odie garfield -- conjecture : jon_hates_jon include jon_owns_garfield include jon_owns_odie theorem jon_hates_jon : hates jon jon := have a1 : hates _ _, from dog_chase_cat _ _ odie_chased_garfield, begin rw jon_owns_garfield.symm at a1, rw jon_owns_odie.symm at a1, assumption end
90e13d4625c817ab31a6e334c4324c819e2871cb
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/tactic/pi_instances_auto.lean
34521c9830e932681397bdba21aed9f0ff49c9e7
[]
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
770
lean
/- Copyright (c) 2018 Simon Hudon All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Simon Hudon -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.order.basic import Mathlib.PostPort namespace Mathlib /-! # `pi_instance` Automation for creating instances of mathematical structures for pi types -/ namespace tactic /-- Attempt to clear a goal obtained by refining a `pi_instance` goal. -/ /-- `pi_instance` constructs an instance of `my_class (Π i : I, f i)` where we know `Π i, my_class (f i)`. If an order relation is required, it defaults to `pi.partial_order`. Any field of the instance that `pi_instance` cannot construct is left untouched and generated as a new goal. -/ end Mathlib
892c53b05e85260aa1659e433368e0c3dc6136a7
3f7026ea8bef0825ca0339a275c03b911baef64d
/src/data/rat/cast.lean
16777952d366c5eb8387d4e88124abb705dcffd8
[ "Apache-2.0" ]
permissive
rspencer01/mathlib
b1e3afa5c121362ef0881012cc116513ab09f18c
c7d36292c6b9234dc40143c16288932ae38fdc12
refs/heads/master
1,595,010,346,708
1,567,511,503,000
1,567,511,503,000
206,071,681
0
0
Apache-2.0
1,567,513,643,000
1,567,513,643,000
null
UTF-8
Lean
false
false
11,744
lean
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import data.rat.order /-! # Casts for Rational Numbers ## Summary We define the canonical injection from ℚ into an arbitrary division ring and prove various casting lemmas showing the well-behavedness of this injection. ## Notations - `/.` is infix notation for `rat.mk`. ## Tags rat, rationals, field, ℚ, numerator, denominator, num, denom, cast, coercion, casting -/ namespace rat variable {α : Type*} local infix ` /. `:70 := rat.mk section with_div_ring variable [division_ring α] /-- Construct the canonical injection from `ℚ` into an arbitrary division ring. If the field has positive characteristic `p`, we define `1 / p = 1 / 0 = 0` for consistency with our division by zero convention. -/ protected def cast : ℚ → α | ⟨n, d, h, c⟩ := n / d @[priority 0] instance cast_coe : has_coe ℚ α := ⟨rat.cast⟩ @[simp] theorem cast_of_int (n : ℤ) : (of_int n : α) = n := show (n / (1:ℕ) : α) = n, by rw [nat.cast_one, div_one] @[simp, squash_cast] theorem cast_coe_int (n : ℤ) : ((n : ℚ) : α) = n := by rw [coe_int_eq_of_int, cast_of_int] @[simp, squash_cast] theorem cast_coe_nat (n : ℕ) : ((n : ℚ) : α) = n := cast_coe_int n @[simp, squash_cast] theorem cast_zero : ((0 : ℚ) : α) = 0 := (cast_of_int _).trans int.cast_zero @[simp, squash_cast] theorem cast_one : ((1 : ℚ) : α) = 1 := (cast_of_int _).trans int.cast_one theorem mul_cast_comm (a : α) : ∀ (n : ℚ), (n.denom : α) ≠ 0 → a * n = n * a | ⟨n, d, h, c⟩ h₂ := show a * (n * d⁻¹) = n * d⁻¹ * a, by rw [← mul_assoc, int.mul_cast_comm, mul_assoc, mul_assoc, ← show (d:α)⁻¹ * a = a * d⁻¹, from division_ring.inv_comm_of_comm h₂ (int.mul_cast_comm a d).symm] @[move_cast] theorem cast_mk_of_ne_zero (a b : ℤ) (b0 : (b:α) ≠ 0) : (a /. b : α) = a / b := begin have b0' : b ≠ 0, { refine mt _ b0, simp {contextual := tt} }, cases e : a /. b with n d h c, have d0 : (d:α) ≠ 0, { intro d0, have dd := denom_dvd a b, cases (show (d:ℤ) ∣ b, by rwa e at dd) with k ke, have : (b:α) = (d:α) * (k:α), {rw [ke, int.cast_mul], refl}, rw [d0, zero_mul] at this, contradiction }, rw [num_denom'] at e, have := congr_arg (coe : ℤ → α) ((mk_eq b0' $ ne_of_gt $ int.coe_nat_pos.2 h).1 e), rw [int.cast_mul, int.cast_mul, int.cast_coe_nat] at this, symmetry, change (a * b⁻¹ : α) = n / d, rw [eq_div_iff_mul_eq _ _ d0, mul_assoc, nat.mul_cast_comm, ← mul_assoc, this, mul_assoc, mul_inv_cancel b0, mul_one] end @[move_cast] theorem cast_add_of_ne_zero : ∀ {m n : ℚ}, (m.denom : α) ≠ 0 → (n.denom : α) ≠ 0 → ((m + n : ℚ) : α) = m + n | ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ := λ (d₁0 : (d₁:α) ≠ 0) (d₂0 : (d₂:α) ≠ 0), begin have d₁0' : (d₁:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d₁0; exact d₁0 rfl), have d₂0' : (d₂:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d₂0; exact d₂0 rfl), rw [num_denom', num_denom', add_def d₁0' d₂0'], suffices : (n₁ * (d₂ * (d₂⁻¹ * d₁⁻¹)) + n₂ * (d₁ * d₂⁻¹) * d₁⁻¹ : α) = n₁ * d₁⁻¹ + n₂ * d₂⁻¹, { rw [cast_mk_of_ne_zero, cast_mk_of_ne_zero, cast_mk_of_ne_zero], { simpa [division_def, left_distrib, right_distrib, mul_inv_eq, d₁0, d₂0, division_ring.mul_ne_zero d₁0 d₂0, mul_assoc] }, all_goals {simp [d₁0, d₂0, division_ring.mul_ne_zero d₁0 d₂0]} }, rw [← mul_assoc (d₂:α), mul_inv_cancel d₂0, one_mul, ← nat.mul_cast_comm], simp [d₁0, mul_assoc] end @[simp, move_cast] theorem cast_neg : ∀ n, ((-n : ℚ) : α) = -n | ⟨n, d, h, c⟩ := show (↑-n * d⁻¹ : α) = -(n * d⁻¹), by rw [int.cast_neg, neg_mul_eq_neg_mul] @[move_cast] theorem cast_sub_of_ne_zero {m n : ℚ} (m0 : (m.denom : α) ≠ 0) (n0 : (n.denom : α) ≠ 0) : ((m - n : ℚ) : α) = m - n := have ((-n).denom : α) ≠ 0, by cases n; exact n0, by simp [(cast_add_of_ne_zero m0 this)] @[move_cast] theorem cast_mul_of_ne_zero : ∀ {m n : ℚ}, (m.denom : α) ≠ 0 → (n.denom : α) ≠ 0 → ((m * n : ℚ) : α) = m * n | ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ := λ (d₁0 : (d₁:α) ≠ 0) (d₂0 : (d₂:α) ≠ 0), begin have d₁0' : (d₁:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d₁0; exact d₁0 rfl), have d₂0' : (d₂:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d₂0; exact d₂0 rfl), rw [num_denom', num_denom', mul_def d₁0' d₂0'], suffices : (n₁ * ((n₂ * d₂⁻¹) * d₁⁻¹) : α) = n₁ * (d₁⁻¹ * (n₂ * d₂⁻¹)), { rw [cast_mk_of_ne_zero, cast_mk_of_ne_zero, cast_mk_of_ne_zero], { simpa [division_def, mul_inv_eq, d₁0, d₂0, division_ring.mul_ne_zero d₁0 d₂0, mul_assoc] }, all_goals {simp [d₁0, d₂0, division_ring.mul_ne_zero d₁0 d₂0]} }, rw [division_ring.inv_comm_of_comm d₁0 (nat.mul_cast_comm _ _).symm] end @[move_cast] theorem cast_inv_of_ne_zero : ∀ {n : ℚ}, (n.num : α) ≠ 0 → (n.denom : α) ≠ 0 → ((n⁻¹ : ℚ) : α) = n⁻¹ | ⟨n, d, h, c⟩ := λ (n0 : (n:α) ≠ 0) (d0 : (d:α) ≠ 0), begin have n0' : (n:ℤ) ≠ 0 := λ e, by rw e at n0; exact n0 rfl, have d0' : (d:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d0; exact d0 rfl), rw [num_denom', inv_def], rw [cast_mk_of_ne_zero, cast_mk_of_ne_zero, inv_div]; simp [n0, d0] end @[move_cast] theorem cast_div_of_ne_zero {m n : ℚ} (md : (m.denom : α) ≠ 0) (nn : (n.num : α) ≠ 0) (nd : (n.denom : α) ≠ 0) : ((m / n : ℚ) : α) = m / n := have (n⁻¹.denom : ℤ) ∣ n.num, by conv in n⁻¹.denom { rw [←(@num_denom n), inv_def] }; apply denom_dvd, have (n⁻¹.denom : α) = 0 → (n.num : α) = 0, from λ h, let ⟨k, e⟩ := this in by have := congr_arg (coe : ℤ → α) e; rwa [int.cast_mul, int.cast_coe_nat, h, zero_mul] at this, by rw [division_def, cast_mul_of_ne_zero md (mt this nn), cast_inv_of_ne_zero nn nd, division_def] @[simp, elim_cast] theorem cast_inj [char_zero α] : ∀ {m n : ℚ}, (m : α) = n ↔ m = n | ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ := begin refine ⟨λ h, _, congr_arg _⟩, have d₁0 : d₁ ≠ 0 := ne_of_gt h₁, have d₂0 : d₂ ≠ 0 := ne_of_gt h₂, have d₁a : (d₁:α) ≠ 0 := nat.cast_ne_zero.2 d₁0, have d₂a : (d₂:α) ≠ 0 := nat.cast_ne_zero.2 d₂0, rw [num_denom', num_denom'] at h ⊢, rw [cast_mk_of_ne_zero, cast_mk_of_ne_zero] at h; simp [d₁0, d₂0] at h ⊢, rwa [eq_div_iff_mul_eq _ _ d₂a, division_def, mul_assoc, division_ring.inv_comm_of_comm d₁a (nat.mul_cast_comm _ _), ← mul_assoc, ← division_def, eq_comm, eq_div_iff_mul_eq _ _ d₁a, eq_comm, ← int.cast_coe_nat, ← int.cast_mul, ← int.cast_coe_nat, ← int.cast_mul, int.cast_inj, ← mk_eq (int.coe_nat_ne_zero.2 d₁0) (int.coe_nat_ne_zero.2 d₂0)] at h end theorem cast_injective [char_zero α] : function.injective (coe : ℚ → α) | m n := cast_inj.1 @[simp] theorem cast_eq_zero [char_zero α] {n : ℚ} : (n : α) = 0 ↔ n = 0 := by rw [← cast_zero, cast_inj] @[simp] theorem cast_ne_zero [char_zero α] {n : ℚ} : (n : α) ≠ 0 ↔ n ≠ 0 := not_congr cast_eq_zero theorem eq_cast_of_ne_zero (f : ℚ → α) (H1 : f 1 = 1) (Hadd : ∀ x y, f (x + y) = f x + f y) (Hmul : ∀ x y, f (x * y) = f x * f y) : ∀ n : ℚ, (n.denom : α) ≠ 0 → f n = n | ⟨n, d, h, c⟩ := λ (h₂ : ((d:ℤ):α) ≠ 0), show _ = (n / (d:ℤ) : α), begin rw [num_denom', mk_eq_div, eq_div_iff_mul_eq _ _ h₂], have : ∀ n : ℤ, f n = n, { apply int.eq_cast; simp [H1, Hadd] }, rw [← this, ← this, ← Hmul, div_mul_cancel], exact int.cast_ne_zero.2 (int.coe_nat_ne_zero.2 $ ne_of_gt h), end theorem eq_cast [char_zero α] (f : ℚ → α) (H1 : f 1 = 1) (Hadd : ∀ x y, f (x + y) = f x + f y) (Hmul : ∀ x y, f (x * y) = f x * f y) (n : ℚ) : f n = n := eq_cast_of_ne_zero _ H1 Hadd Hmul _ $ nat.cast_ne_zero.2 $ ne_of_gt n.pos end with_div_ring @[move_cast] theorem cast_mk [discrete_field α] [char_zero α] (a b : ℤ) : ((a /. b) : α) = a / b := if b0 : b = 0 then by simp [b0, div_zero] else cast_mk_of_ne_zero a b (int.cast_ne_zero.2 b0) @[simp, move_cast] theorem cast_add [division_ring α] [char_zero α] (m n) : ((m + n : ℚ) : α) = m + n := cast_add_of_ne_zero (nat.cast_ne_zero.2 $ ne_of_gt m.pos) (nat.cast_ne_zero.2 $ ne_of_gt n.pos) @[simp, move_cast] theorem cast_sub [division_ring α] [char_zero α] (m n) : ((m - n : ℚ) : α) = m - n := cast_sub_of_ne_zero (nat.cast_ne_zero.2 $ ne_of_gt m.pos) (nat.cast_ne_zero.2 $ ne_of_gt n.pos) @[simp, move_cast] theorem cast_mul [division_ring α] [char_zero α] (m n) : ((m * n : ℚ) : α) = m * n := cast_mul_of_ne_zero (nat.cast_ne_zero.2 $ ne_of_gt m.pos) (nat.cast_ne_zero.2 $ ne_of_gt n.pos) @[simp, move_cast] theorem cast_inv [discrete_field α] [char_zero α] (n) : ((n⁻¹ : ℚ) : α) = n⁻¹ := if n0 : n.num = 0 then by simp [show n = 0, by rw [←(@num_denom n), n0]; simp, inv_zero] else cast_inv_of_ne_zero (int.cast_ne_zero.2 n0) (nat.cast_ne_zero.2 $ ne_of_gt n.pos) @[simp, move_cast] theorem cast_div [discrete_field α] [char_zero α] (m n) : ((m / n : ℚ) : α) = m / n := by rw [division_def, cast_mul, cast_inv, division_def] @[simp, move_cast] theorem cast_pow [discrete_field α] [char_zero α] (q) (k : ℕ) : ((q ^ k : ℚ) : α) = q ^ k := by induction k; simp only [*, cast_one, cast_mul, pow_zero, pow_succ] @[simp, squash_cast, move_cast] theorem cast_bit0 [division_ring α] [char_zero α] (n : ℚ) : ((bit0 n : ℚ) : α) = bit0 n := cast_add _ _ @[simp, squash_cast, move_cast] theorem cast_bit1 [division_ring α] [char_zero α] (n : ℚ) : ((bit1 n : ℚ) : α) = bit1 n := by rw [bit1, cast_add, cast_one, cast_bit0]; refl @[simp] theorem cast_nonneg [linear_ordered_field α] : ∀ {n : ℚ}, 0 ≤ (n : α) ↔ 0 ≤ n | ⟨n, d, h, c⟩ := show 0 ≤ (n * d⁻¹ : α) ↔ 0 ≤ (⟨n, d, h, c⟩ : ℚ), by rw [num_denom', ← nonneg_iff_zero_le, mk_nonneg _ (int.coe_nat_pos.2 h), mul_nonneg_iff_right_nonneg_of_pos (@inv_pos α _ _ (nat.cast_pos.2 h)), int.cast_nonneg] @[simp, elim_cast] theorem cast_le [linear_ordered_field α] {m n : ℚ} : (m : α) ≤ n ↔ m ≤ n := by rw [← sub_nonneg, ← cast_sub, cast_nonneg, sub_nonneg] @[simp, elim_cast] theorem cast_lt [linear_ordered_field α] {m n : ℚ} : (m : α) < n ↔ m < n := by simpa [-cast_le] using not_congr (@cast_le α _ n m) @[simp] theorem cast_nonpos [linear_ordered_field α] {n : ℚ} : (n : α) ≤ 0 ↔ n ≤ 0 := by rw [← cast_zero, cast_le] @[simp] theorem cast_pos [linear_ordered_field α] {n : ℚ} : (0 : α) < n ↔ 0 < n := by rw [← cast_zero, cast_lt] @[simp] theorem cast_lt_zero [linear_ordered_field α] {n : ℚ} : (n : α) < 0 ↔ n < 0 := by rw [← cast_zero, cast_lt] @[simp, squash_cast] theorem cast_id : ∀ n : ℚ, ↑n = n | ⟨n, d, h, c⟩ := show (n / (d : ℤ) : ℚ) = _, by rw [num_denom', mk_eq_div] @[simp, move_cast] theorem cast_min [discrete_linear_ordered_field α] {a b : ℚ} : (↑(min a b) : α) = min a b := by by_cases a ≤ b; simp [h, min] @[simp, move_cast] theorem cast_max [discrete_linear_ordered_field α] {a b : ℚ} : (↑(max a b) : α) = max a b := by by_cases a ≤ b; simp [h, max] @[simp, move_cast] theorem cast_abs [discrete_linear_ordered_field α] {q : ℚ} : ((abs q : ℚ) : α) = abs q := by simp [abs] end rat
a235fa4b0dac171045b3862c025af4ae0dcbfa86
3f7026ea8bef0825ca0339a275c03b911baef64d
/src/group_theory/submonoid.lean
04eefdf6f3097247f4645a51cf749d022d6874c3
[ "Apache-2.0" ]
permissive
rspencer01/mathlib
b1e3afa5c121362ef0881012cc116513ab09f18c
c7d36292c6b9234dc40143c16288932ae38fdc12
refs/heads/master
1,595,010,346,708
1,567,511,503,000
1,567,511,503,000
206,071,681
0
0
Apache-2.0
1,567,513,643,000
1,567,513,643,000
null
UTF-8
Lean
false
false
11,493
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, Kenny Lau, Johan Commelin, Mario Carneiro -/ import algebra.big_operators import data.finset import tactic.subtype_instance variables {α : Type*} [monoid α] {s : set α} variables {β : Type*} [add_monoid β] {t : set β} /-- `s` is an additive submonoid: a set containing 0 and closed under addition. -/ class is_add_submonoid (s : set β) : Prop := (zero_mem : (0:β) ∈ s) (add_mem {a b} : a ∈ s → b ∈ s → a + b ∈ s) /-- `s` is a submonoid: a set containing 1 and closed under multiplication. -/ @[to_additive is_add_submonoid] class is_submonoid (s : set α) : Prop := (one_mem : (1:α) ∈ s) (mul_mem {a b} : a ∈ s → b ∈ s → a * b ∈ s) instance additive.is_add_submonoid (s : set α) : ∀ [is_submonoid s], @is_add_submonoid (additive α) _ s | ⟨h₁, h₂⟩ := ⟨h₁, @h₂⟩ theorem additive.is_add_submonoid_iff {s : set α} : @is_add_submonoid (additive α) _ s ↔ is_submonoid s := ⟨λ ⟨h₁, h₂⟩, ⟨h₁, @h₂⟩, λ h, by resetI; apply_instance⟩ instance multiplicative.is_submonoid (s : set β) : ∀ [is_add_submonoid s], @is_submonoid (multiplicative β) _ s | ⟨h₁, h₂⟩ := ⟨h₁, @h₂⟩ theorem multiplicative.is_submonoid_iff {s : set β} : @is_submonoid (multiplicative β) _ s ↔ is_add_submonoid s := ⟨λ ⟨h₁, h₂⟩, ⟨h₁, @h₂⟩, λ h, by resetI; apply_instance⟩ @[to_additive] lemma is_submonoid.inter (s₁ s₂ : set α) [is_submonoid s₁] [is_submonoid s₂] : is_submonoid (s₁ ∩ s₂) := { one_mem := ⟨is_submonoid.one_mem _, is_submonoid.one_mem _⟩, mul_mem := λ x y hx hy, ⟨is_submonoid.mul_mem hx.1 hy.1, is_submonoid.mul_mem hx.2 hy.2⟩ } @[to_additive is_add_submonoid_Union_of_directed] lemma is_submonoid_Union_of_directed {ι : Type*} [hι : nonempty ι] (s : ι → set α) [∀ i, is_submonoid (s i)] (directed : ∀ i j, ∃ k, s i ⊆ s k ∧ s j ⊆ s k) : is_submonoid (⋃i, s i) := { one_mem := let ⟨i⟩ := hι in set.mem_Union.2 ⟨i, is_submonoid.one_mem _⟩, mul_mem := λ a b ha hb, let ⟨i, hi⟩ := set.mem_Union.1 ha in let ⟨j, hj⟩ := set.mem_Union.1 hb in let ⟨k, hk⟩ := directed i j in set.mem_Union.2 ⟨k, is_submonoid.mul_mem (hk.1 hi) (hk.2 hj)⟩ } section powers def powers (x : α) : set α := {y | ∃ n:ℕ, x^n = y} def multiples (x : β) : set β := {y | ∃ n:ℕ, add_monoid.smul n x = y} attribute [to_additive multiples] powers lemma powers.one_mem {x : α} : (1 : α) ∈ powers x := ⟨0, pow_zero _⟩ lemma multiples.zero_mem {x : β} : (0 : β) ∈ multiples x := ⟨0, add_monoid.zero_smul _⟩ attribute [to_additive] powers.one_mem lemma powers.self_mem {x : α} : x ∈ powers x := ⟨1, pow_one _⟩ lemma multiples.self_mem {x : β} : x ∈ multiples x := ⟨1, add_monoid.one_smul _⟩ attribute [to_additive] powers.self_mem lemma powers.mul_mem {x y z: α} : (y ∈ powers x) → (z ∈ powers x) → (y * z ∈ powers x) := λ ⟨n₁, h₁⟩ ⟨n₂, h₂⟩, ⟨n₁ + n₂, by simp only [pow_add, *]⟩ lemma multiples.add_mem {x y z: β} : (y ∈ multiples x) → (z ∈ multiples x) → (y + z ∈ multiples x) := @powers.mul_mem (multiplicative β) _ _ _ _ attribute [to_additive] powers.mul_mem @[to_additive is_add_submonoid] instance powers.is_submonoid (x : α) : is_submonoid (powers x) := { one_mem := powers.one_mem, mul_mem := λ y z, powers.mul_mem } @[to_additive is_add_submonoid] instance univ.is_submonoid : is_submonoid (@set.univ α) := by split; simp @[to_additive is_add_submonoid] instance preimage.is_submonoid {γ : Type*} [monoid γ] (f : α → γ) [is_monoid_hom f] (s : set γ) [is_submonoid s] : is_submonoid (f ⁻¹' s) := { one_mem := show f 1 ∈ s, by rw is_monoid_hom.map_one f; exact is_submonoid.one_mem s, mul_mem := λ a b (ha : f a ∈ s) (hb : f b ∈ s), show f (a * b) ∈ s, by rw is_monoid_hom.map_mul f; exact is_submonoid.mul_mem ha hb } @[instance, to_additive is_add_submonoid] lemma image.is_submonoid {γ : Type*} [monoid γ] (f : α → γ) [is_monoid_hom f] (s : set α) [is_submonoid s] : is_submonoid (f '' s) := { one_mem := ⟨1, is_submonoid.one_mem s, is_monoid_hom.map_one f⟩, mul_mem := λ a b ⟨x, hx⟩ ⟨y, hy⟩, ⟨x * y, is_submonoid.mul_mem hx.1 hy.1, by rw [is_monoid_hom.map_mul f, hx.2, hy.2]⟩ } @[to_additive is_add_submonoid] instance range.is_submonoid {γ : Type*} [monoid γ] (f : α → γ) [is_monoid_hom f] : is_submonoid (set.range f) := by rw ← set.image_univ; apply_instance lemma is_submonoid.pow_mem {a : α} [is_submonoid s] (h : a ∈ s) : ∀ {n : ℕ}, a ^ n ∈ s | 0 := is_submonoid.one_mem s | (n + 1) := is_submonoid.mul_mem h is_submonoid.pow_mem lemma is_add_submonoid.smul_mem {a : β} [is_add_submonoid t] : ∀ (h : a ∈ t) {n : ℕ}, add_monoid.smul n a ∈ t := @is_submonoid.pow_mem (multiplicative β) _ _ _ _ attribute [to_additive smul_mem] is_submonoid.pow_mem lemma is_submonoid.power_subset {a : α} [is_submonoid s] (h : a ∈ s) : powers a ⊆ s := assume x ⟨n, hx⟩, hx ▸ is_submonoid.pow_mem h lemma is_add_submonoid.multiple_subset {a : β} [is_add_submonoid t] : a ∈ t → multiples a ⊆ t := @is_submonoid.power_subset (multiplicative β) _ _ _ _ attribute [to_additive multiple_subset] is_submonoid.power_subset end powers namespace is_submonoid @[to_additive] lemma list_prod_mem [is_submonoid s] : ∀{l : list α}, (∀x∈l, x ∈ s) → l.prod ∈ s | [] h := one_mem s | (a::l) h := suffices a * l.prod ∈ s, by simpa, have a ∈ s ∧ (∀x∈l, x ∈ s), by simpa using h, is_submonoid.mul_mem this.1 (list_prod_mem this.2) @[to_additive] lemma multiset_prod_mem {α} [comm_monoid α] (s : set α) [is_submonoid s] (m : multiset α) : (∀a∈m, a ∈ s) → m.prod ∈ s := begin refine quotient.induction_on m (assume l hl, _), rw [multiset.quot_mk_to_coe, multiset.coe_prod], exact list_prod_mem hl end @[to_additive] lemma finset_prod_mem {α β} [comm_monoid α] (s : set α) [is_submonoid s] (f : β → α) : ∀(t : finset β), (∀b∈t, f b ∈ s) → t.prod f ∈ s | ⟨m, hm⟩ hs := begin refine multiset_prod_mem s _ _, simp, rintros a b hb rfl, exact hs _ hb end end is_submonoid @[to_additive add_monoid] instance subtype.monoid {s : set α} [is_submonoid s] : monoid s := by subtype_instance @[simp, to_additive] lemma is_submonoid.coe_one [is_submonoid s] : ((1 : s) : α) = 1 := rfl @[simp, to_additive] lemma is_submonoid.coe_mul [is_submonoid s] (a b : s) : ((a * b : s) : α) = a * b := rfl @[simp] lemma is_submonoid.coe_pow [is_submonoid s] (a : s) (n : ℕ) : ((a ^ n : s) : α) = a ^ n := by induction n; simp [*, pow_succ] @[simp] lemma is_add_submonoid.smul_coe {β : Type*} [add_monoid β] {s : set β} [is_add_submonoid s] (a : s) (n : ℕ) : ((add_monoid.smul n a : s) : β) = add_monoid.smul n a := by induction n; [refl, simp [*, succ_smul]] attribute [to_additive smul_coe] is_submonoid.coe_pow @[to_additive is_add_monoid_hom] instance subtype_val.is_monoid_hom [is_submonoid s] : is_monoid_hom (subtype.val : s → α) := { map_one := rfl, map_mul := λ _ _, rfl } @[to_additive is_add_monoid_hom] instance coe.is_monoid_hom [is_submonoid s] : is_monoid_hom (coe : s → α) := subtype_val.is_monoid_hom @[to_additive is_add_monoid_hom] instance subtype_mk.is_monoid_hom {γ : Type*} [monoid γ] [is_submonoid s] (f : γ → α) [is_monoid_hom f] (h : ∀ x, f x ∈ s) : is_monoid_hom (λ x, (⟨f x, h x⟩ : s)) := { map_one := subtype.eq (is_monoid_hom.map_one f), map_mul := λ x y, subtype.eq (is_monoid_hom.map_mul f x y) } @[to_additive is_add_monoid_hom] instance set_inclusion.is_monoid_hom (t : set α) [is_submonoid s] [is_submonoid t] (h : s ⊆ t) : is_monoid_hom (set.inclusion h) := subtype_mk.is_monoid_hom _ _ namespace add_monoid inductive in_closure (s : set β) : β → Prop | basic {a : β} : a ∈ s → in_closure a | zero : in_closure 0 | add {a b : β} : in_closure a → in_closure b → in_closure (a + b) end add_monoid namespace monoid inductive in_closure (s : set α) : α → Prop | basic {a : α} : a ∈ s → in_closure a | one : in_closure 1 | mul {a b : α} : in_closure a → in_closure b → in_closure (a * b) attribute [to_additive] monoid.in_closure attribute [to_additive] monoid.in_closure.one attribute [to_additive] monoid.in_closure.mul @[to_additive] def closure (s : set α) : set α := {a | in_closure s a } @[to_additive is_add_submonoid] instance closure.is_submonoid (s : set α) : is_submonoid (closure s) := { one_mem := in_closure.one s, mul_mem := assume a b, in_closure.mul } @[to_additive] theorem subset_closure {s : set α} : s ⊆ closure s := assume a, in_closure.basic @[to_additive] theorem closure_subset {s t : set α} [is_submonoid t] (h : s ⊆ t) : closure s ⊆ t := assume a ha, by induction ha; simp [h _, *, is_submonoid.one_mem, is_submonoid.mul_mem] @[to_additive] theorem closure_mono {s t : set α} (h : s ⊆ t) : closure s ⊆ closure t := closure_subset $ set.subset.trans h subset_closure @[to_additive] theorem closure_singleton {x : α} : closure ({x} : set α) = powers x := set.eq_of_subset_of_subset (closure_subset $ set.singleton_subset_iff.2 $ powers.self_mem) $ is_submonoid.power_subset $ set.singleton_subset_iff.1 $ subset_closure @[to_additive] lemma image_closure {β : Type*} [monoid β] (f : α → β) [is_monoid_hom f] (s : set α) : f '' closure s = closure (f '' s) := le_antisymm begin rintros _ ⟨x, hx, rfl⟩, apply in_closure.rec_on hx; intros, { solve_by_elim [subset_closure, set.mem_image_of_mem] }, { rw [is_monoid_hom.map_one f], apply is_submonoid.one_mem }, { rw [is_monoid_hom.map_mul f], solve_by_elim [is_submonoid.mul_mem] } end (closure_subset $ set.image_subset _ subset_closure) @[to_additive] theorem exists_list_of_mem_closure {s : set α} {a : α} (h : a ∈ closure s) : (∃l:list α, (∀x∈l, x ∈ s) ∧ l.prod = a) := begin induction h, case in_closure.basic : a ha { existsi ([a]), simp [ha] }, case in_closure.one { existsi ([]), simp }, case in_closure.mul : a b _ _ ha hb { rcases ha with ⟨la, ha, eqa⟩, rcases hb with ⟨lb, hb, eqb⟩, existsi (la ++ lb), simp [eqa.symm, eqb.symm, or_imp_distrib], exact assume a, ⟨ha a, hb a⟩ } end @[to_additive] theorem mem_closure_union_iff {α : Type*} [comm_monoid α] {s t : set α} {x : α} : x ∈ closure (s ∪ t) ↔ ∃ y ∈ closure s, ∃ z ∈ closure t, y * z = x := ⟨λ hx, let ⟨L, HL1, HL2⟩ := exists_list_of_mem_closure hx in HL2 ▸ list.rec_on L (λ _, ⟨1, is_submonoid.one_mem _, 1, is_submonoid.one_mem _, mul_one _⟩) (λ hd tl ih HL1, let ⟨y, hy, z, hz, hyzx⟩ := ih (list.forall_mem_of_forall_mem_cons HL1) in or.cases_on (HL1 hd $ list.mem_cons_self _ _) (λ hs, ⟨hd * y, is_submonoid.mul_mem (subset_closure hs) hy, z, hz, by rw [mul_assoc, list.prod_cons, ← hyzx]; refl⟩) (λ ht, ⟨y, hy, z * hd, is_submonoid.mul_mem hz (subset_closure ht), by rw [← mul_assoc, list.prod_cons, ← hyzx, mul_comm hd]; refl⟩)) HL1, λ ⟨y, hy, z, hz, hyzx⟩, hyzx ▸ is_submonoid.mul_mem (closure_mono (set.subset_union_left _ _) hy) (closure_mono (set.subset_union_right _ _) hz)⟩ end monoid
5e568f70fd58f94265417c66794fc1cf33b36c4e
0bd6c950c82dcba3e46dc8d8acb5ecc60b917520
/konigsberg.lean
7417263a381384f9d7ab5b3fbce36b4f651951b3
[]
no_license
truonghoangle/formalabstracts
976dbbdede5c71346a3c534a8f319456248d4610
b889ec60143315053a51b1829a5dc4d82ba503b3
refs/heads/master
1,584,899,948,798
1,537,184,894,000
1,537,184,894,000
140,428,980
0
0
null
null
null
null
UTF-8
Lean
false
false
1,111
lean
import data.set.basic open set variables {α :Type} {β : Type} def edges (G:set α× set β × (α→ set β)) :set α := G.1 def vertices (G:set α× set β × (α→ set β)) :set β := G.2.1 def termini (G:set α× set β × (α→ set β)) :α → set β := G.2.2 def connects (G:set α× set β × (α→ set β)) (e:α) (a:β × β ):Prop:= termini G e ={a.1,a.2} def delete_edge (e:α) (G:set α× set β × (α→ set β)):set α× set β × (α→ set β):= ((edges G) \ {e}, vertices G, termini G ) def eulerian :(set α× set β × (α→ set β)) → list α → β × β → Prop |G [] a := edges G = {} ∧ a.1=a.2 ∧ a.1 ∈ vertices G |G (ee :: l) a := ∃ (c:β), ee ∈ edges(G) ∧ connects G ee a ∧ eulerian (delete_edge ee G) l (a.2,c) def V:set ℕ :={1,2,3,4} def E:set ℕ :={1,2,3,4,5,6,7} def Ter (e:ℕ):set ℕ := match e with |1 :={1,2} |2 :={1,2} |3 :={1,4} |4 :={1,4} |5 :={1,3} |6 :={2,3} |7 :={3,4} |_ :={} end theorem konigsberg : ¬ (∃ l a b, eulerian (E,V,Ter) l (a,b)) := sorry
3f4c905d98f2fcbfd145fdb43ff9fa75cb3bd148
ad0c7d243dc1bd563419e2767ed42fb323d7beea
/data/nat/sqrt.lean
4a72800c88af134be2ad79afc92db7fbd69d8158
[ "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
6,808
lean
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Johannes Hölzl, Mario Carneiro An efficient binary implementation of a (sqrt n) function that returns s s.t. s*s ≤ n ≤ s*s + s + s -/ import data.nat.basic algebra.ordered_group algebra.ring tactic namespace nat theorem sqrt_aux_dec {b} (h : b ≠ 0) : shiftr b 2 < b := begin simp [shiftr_eq_div_pow], apply (nat.div_lt_iff_lt_mul _ _ (dec_trivial : 4 > 0)).2, have := nat.mul_lt_mul_of_pos_left (dec_trivial : 1 < 4) (nat.pos_of_ne_zero h), rwa mul_one at this end def sqrt_aux : ℕ → ℕ → ℕ → ℕ | b r n := if b0 : b = 0 then r else let b' := shiftr b 2 in have b' < b, from sqrt_aux_dec b0, match (n - (r + b : ℕ) : ℤ) with | (n' : ℕ) := sqrt_aux b' (div2 r + b) n' | _ := sqrt_aux b' (div2 r) n end /-- `sqrt n` is the square root of a natural number `n`. If `n` is not a perfect square, it returns the largest `k:ℕ` such that `k*k ≤ n`. -/ def sqrt (n : ℕ) : ℕ := match size n with | 0 := 0 | succ s := sqrt_aux (shiftl 1 (bit0 (div2 s))) 0 n end theorem sqrt_aux_0 (r n) : sqrt_aux 0 r n = r := by rw sqrt_aux; simp local attribute [simp] sqrt_aux_0 theorem sqrt_aux_1 {r n b} (h : b ≠ 0) {n'} (h₂ : r + b + n' = n) : sqrt_aux b r n = sqrt_aux (shiftr b 2) (div2 r + b) n' := by rw sqrt_aux; simp only [h, h₂.symm, int.coe_nat_add, if_false]; rw [add_comm _ (n':ℤ), add_sub_cancel, sqrt_aux._match_1] theorem sqrt_aux_2 {r n b} (h : b ≠ 0) (h₂ : n < r + b) : sqrt_aux b r n = sqrt_aux (shiftr b 2) (div2 r) n := begin rw sqrt_aux; simp only [h, h₂, if_false], cases int.eq_neg_succ_of_lt_zero (sub_lt_zero.2 (int.coe_nat_lt_coe_nat_of_lt h₂)) with k e, rw [e, sqrt_aux._match_1] end private def is_sqrt (n q : ℕ) : Prop := q*q ≤ n ∧ n < (q+1)*(q+1) private lemma sqrt_aux_is_sqrt_lemma (m r n : ℕ) (h₁ : r*r ≤ n) (m') (hm : shiftr (2^m * 2^m) 2 = m') (H1 : n < (r + 2^m) * (r + 2^m) → is_sqrt n (sqrt_aux m' (r * 2^m) (n - r * r))) (H2 : (r + 2^m) * (r + 2^m) ≤ n → is_sqrt n (sqrt_aux m' ((r + 2^m) * 2^m) (n - (r + 2^m) * (r + 2^m)))) : is_sqrt n (sqrt_aux (2^m * 2^m) ((2*r)*2^m) (n - r*r)) := begin have b0 := have b0:_, from ne_of_gt (@pos_pow_of_pos 2 m dec_trivial), nat.mul_ne_zero b0 b0, have lb : n - r * r < 2 * r * 2^m + 2^m * 2^m ↔ n < (r+2^m)*(r+2^m), { rw [nat.sub_lt_right_iff_lt_add h₁], simp [left_distrib, right_distrib, two_mul, mul_comm, mul_assoc] }, have re : div2 (2 * r * 2^m) = r * 2^m, { rw [div2_val, mul_assoc, nat.mul_div_cancel_left _ (dec_trivial:2>0)] }, cases lt_or_ge n ((r+2^m)*(r+2^m)) with hl hl, { rw [sqrt_aux_2 b0 (lb.2 hl), hm, re], apply H1 hl }, { cases le.dest hl with n' e, rw [@sqrt_aux_1 (2 * r * 2^m) (n-r*r) (2^m * 2^m) b0 (n - (r + 2^m) * (r + 2^m)), hm, re, ← right_distrib], { apply H2 hl }, apply eq.symm, apply nat.sub_eq_of_eq_add, rw [← add_assoc, (_ : r*r + _ = _)], exact (nat.add_sub_cancel' hl).symm, simp [left_distrib, right_distrib, two_mul, mul_comm, mul_assoc] }, end private lemma sqrt_aux_is_sqrt (n) : ∀ m r, r*r ≤ n → n < (r + 2^(m+1)) * (r + 2^(m+1)) → is_sqrt n (sqrt_aux (2^m * 2^m) (2*r*2^m) (n - r*r)) | 0 r h₁ h₂ := by apply sqrt_aux_is_sqrt_lemma 0 r n h₁ 0 rfl; intros; simp; [exact ⟨h₁, a⟩, exact ⟨a, h₂⟩] | (m+1) r h₁ h₂ := begin apply sqrt_aux_is_sqrt_lemma (m+1) r n h₁ (2^m * 2^m) (by simp [shiftr, pow_succ, div2_val, mul_comm, mul_left_comm]; repeat {rw @nat.mul_div_cancel_left _ 2 dec_trivial}); intros, { have := sqrt_aux_is_sqrt m r h₁ a, simpa [pow_succ, mul_comm, mul_assoc] }, { rw [pow_succ, mul_two, ← add_assoc] at h₂, have := sqrt_aux_is_sqrt m (r + 2^(m+1)) a h₂, rwa show (r + 2^(m + 1)) * 2^(m+1) = 2 * (r + 2^(m + 1)) * 2^m, by simp [pow_succ, mul_comm, mul_left_comm] } end private lemma sqrt_is_sqrt (n : ℕ) : is_sqrt n (sqrt n) := begin generalize e : size n = s, cases s with s; simp [e, sqrt], { rw [size_eq_zero.1 e, is_sqrt], exact dec_trivial }, { have := sqrt_aux_is_sqrt n (div2 s) 0 (zero_le _), simp [show 2^div2 s * 2^div2 s = shiftl 1 (bit0 (div2 s)), by { generalize: div2 s = x, change bit0 x with x+x, rw [one_shiftl, pow_add] }] at this, apply this, rw [← pow_add, ← mul_two], apply size_le.1, rw e, apply (@div_lt_iff_lt_mul _ _ 2 dec_trivial).1, rw [div2_val], apply lt_succ_self } end theorem sqrt_le (n : ℕ) : sqrt n * sqrt n ≤ n := (sqrt_is_sqrt n).left theorem lt_succ_sqrt (n : ℕ) : n < succ (sqrt n) * succ (sqrt n) := (sqrt_is_sqrt n).right theorem sqrt_le_add (n : ℕ) : n ≤ sqrt n * sqrt n + sqrt n + sqrt n := by rw ← succ_mul; exact le_of_lt_succ (lt_succ_sqrt n) theorem le_sqrt {m n : ℕ} : m ≤ sqrt n ↔ m*m ≤ n := ⟨λ h, le_trans (mul_self_le_mul_self h) (sqrt_le n), λ h, le_of_lt_succ $ mul_self_lt_mul_self_iff.2 $ lt_of_le_of_lt h (lt_succ_sqrt n)⟩ theorem sqrt_lt {m n : ℕ} : sqrt m < n ↔ m < n*n := le_iff_le_iff_lt_iff_lt.1 le_sqrt theorem sqrt_le_self (n : ℕ) : sqrt n ≤ n := le_trans (le_mul_self _) (sqrt_le n) theorem sqrt_le_sqrt {m n : ℕ} (h : m ≤ n) : sqrt m ≤ sqrt n := le_sqrt.2 (le_trans (sqrt_le _) h) theorem sqrt_eq_zero {n : ℕ} : sqrt n = 0 ↔ n = 0 := ⟨λ h, eq_zero_of_le_zero $ le_of_lt_succ $ (@sqrt_lt n 1).1 $ by rw [h]; exact dec_trivial, λ e, e.symm ▸ rfl⟩ theorem eq_sqrt {n q} : q = sqrt n ↔ q*q ≤ n ∧ n < (q+1)*(q+1) := ⟨λ e, e.symm ▸ sqrt_is_sqrt n, λ ⟨h₁, h₂⟩, le_antisymm (le_sqrt.2 h₁) (le_of_lt_succ $ sqrt_lt.2 h₂)⟩ theorem le_three_of_sqrt_eq_one {n : ℕ} (h : sqrt n = 1) : n ≤ 3 := le_of_lt_succ $ (@sqrt_lt n 2).1 $ by rw [h]; exact dec_trivial theorem sqrt_lt_self {n : ℕ} (h : n > 1) : sqrt n < n := sqrt_lt.2 $ by have := nat.mul_lt_mul_of_pos_left h (lt_of_succ_lt h); rwa [mul_one] at this theorem sqrt_pos {n : ℕ} : sqrt n > 0 ↔ n > 0 := le_sqrt theorem sqrt_add_eq (n : ℕ) {a : ℕ} (h : a ≤ n + n) : sqrt (n*n + a) = n := le_antisymm (le_of_lt_succ $ sqrt_lt.2 $ by rw [succ_mul, mul_succ, add_succ, add_assoc]; exact lt_succ_of_le (nat.add_le_add_left h _)) (le_sqrt.2 $ nat.le_add_right _ _) theorem sqrt_eq (n : ℕ) : sqrt (n*n) = n := sqrt_add_eq n (zero_le _) theorem sqrt_succ_le_succ_sqrt (n : ℕ) : sqrt n.succ ≤ n.sqrt.succ := le_of_lt_succ $ sqrt_lt.2 $ lt_succ_of_le $ succ_le_succ $ le_trans (sqrt_le_add n) $ add_le_add_right (by refine add_le_add (mul_le_mul_right _ _) _; exact le_add_right _ 2) _ end nat
ee51c0e26e274de2dd39267df50a6b153c449a16
80b18137872dad7c3df334b9069d70935b4224f3
/src/data/finset.lean
d08e68d7b0aa4c173ae7527289089772ca33c004
[ "Apache-2.0" ]
permissive
Jack-Pumpkinhead/mathlib
1bcf5692d355dc397847791c137158f01b407535
da8b23f907f750528539bffa604875b98717fb93
refs/heads/master
1,621,299,949,262
1,585,480,767,000
1,585,480,767,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
112,255
lean
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro Finite sets. -/ import logic.embedding algebra.order_functions data.multiset data.sigma.basic data.set.lattice tactic.monotonicity tactic.apply open multiset subtype nat variables {α : Type*} {β : Type*} {γ : Type*} /-- `finset α` is the type of finite sets of elements of `α`. It is implemented as a multiset (a list up to permutation) which has no duplicate elements. -/ structure finset (α : Type*) := (val : multiset α) (nodup : nodup val) namespace finset theorem eq_of_veq : ∀ {s t : finset α}, s.1 = t.1 → s = t | ⟨s, _⟩ ⟨t, _⟩ rfl := rfl @[simp] theorem val_inj {s t : finset α} : s.1 = t.1 ↔ s = t := ⟨eq_of_veq, congr_arg _⟩ @[simp] theorem erase_dup_eq_self [decidable_eq α] (s : finset α) : erase_dup s.1 = s.1 := erase_dup_eq_self.2 s.2 instance has_decidable_eq [decidable_eq α] : decidable_eq (finset α) | s₁ s₂ := decidable_of_iff _ val_inj /- membership -/ instance : has_mem α (finset α) := ⟨λ a s, a ∈ s.1⟩ theorem mem_def {a : α} {s : finset α} : a ∈ s ↔ a ∈ s.1 := iff.rfl @[simp] theorem mem_mk {a : α} {s nd} : a ∈ @finset.mk α s nd ↔ a ∈ s := iff.rfl instance decidable_mem [h : decidable_eq α] (a : α) (s : finset α) : decidable (a ∈ s) := multiset.decidable_mem _ _ /-! ### set coercion -/ /-- Convert a finset to a set in the natural way. -/ def to_set (s : finset α) : set α := {x | x ∈ s} instance : has_lift (finset α) (set α) := ⟨to_set⟩ @[simp] lemma mem_coe {a : α} {s : finset α} : a ∈ (↑s : set α) ↔ a ∈ s := iff.rfl @[simp] lemma set_of_mem {α} {s : finset α} : {a | a ∈ s} = ↑s := rfl instance decidable_mem' [decidable_eq α] (a : α) (s : finset α) : decidable (a ∈ (↑s : set α)) := s.decidable_mem _ /-! ### extensionality -/ theorem ext {s₁ s₂ : finset α} : s₁ = s₂ ↔ ∀ a, a ∈ s₁ ↔ a ∈ s₂ := val_inj.symm.trans $ nodup_ext s₁.2 s₂.2 @[ext] theorem ext' {s₁ s₂ : finset α} : (∀ a, a ∈ s₁ ↔ a ∈ s₂) → s₁ = s₂ := ext.2 @[simp] theorem coe_inj {s₁ s₂ : finset α} : (↑s₁ : set α) = ↑s₂ ↔ s₁ = s₂ := (set.ext_iff _ _).trans ext.symm lemma to_set_injective {α} : function.injective (finset.to_set : finset α → set α) := λ s t, coe_inj.1 /-! ### subset -/ instance : has_subset (finset α) := ⟨λ s₁ s₂, ∀ ⦃a⦄, a ∈ s₁ → a ∈ s₂⟩ theorem subset_def {s₁ s₂ : finset α} : s₁ ⊆ s₂ ↔ s₁.1 ⊆ s₂.1 := iff.rfl @[simp] theorem subset.refl (s : finset α) : s ⊆ s := subset.refl _ theorem subset.trans {s₁ s₂ s₃ : finset α} : s₁ ⊆ s₂ → s₂ ⊆ s₃ → s₁ ⊆ s₃ := subset.trans theorem superset.trans {s₁ s₂ s₃ : finset α} : s₁ ⊇ s₂ → s₂ ⊇ s₃ → s₁ ⊇ s₃ := λ h' h, subset.trans h h' -- TODO: these should be global attributes, but this will require fixing other files local attribute [trans] subset.trans superset.trans theorem mem_of_subset {s₁ s₂ : finset α} {a : α} : s₁ ⊆ s₂ → a ∈ s₁ → a ∈ s₂ := mem_of_subset theorem subset.antisymm {s₁ s₂ : finset α} (H₁ : s₁ ⊆ s₂) (H₂ : s₂ ⊆ s₁) : s₁ = s₂ := ext.2 $ λ a, ⟨@H₁ a, @H₂ a⟩ theorem subset_iff {s₁ s₂ : finset α} : s₁ ⊆ s₂ ↔ ∀ ⦃x⦄, x ∈ s₁ → x ∈ s₂ := iff.rfl @[simp] theorem coe_subset {s₁ s₂ : finset α} : (↑s₁ : set α) ⊆ ↑s₂ ↔ s₁ ⊆ s₂ := iff.rfl @[simp] theorem val_le_iff {s₁ s₂ : finset α} : s₁.1 ≤ s₂.1 ↔ s₁ ⊆ s₂ := le_iff_subset s₁.2 instance : has_ssubset (finset α) := ⟨λa b, a ⊆ b ∧ ¬ b ⊆ a⟩ instance : partial_order (finset α) := { le := (⊆), lt := (⊂), le_refl := subset.refl, le_trans := @subset.trans _, le_antisymm := @subset.antisymm _ } theorem subset.antisymm_iff {s₁ s₂ : finset α} : s₁ = s₂ ↔ s₁ ⊆ s₂ ∧ s₂ ⊆ s₁ := le_antisymm_iff @[simp] theorem le_iff_subset {s₁ s₂ : finset α} : s₁ ≤ s₂ ↔ s₁ ⊆ s₂ := iff.rfl @[simp] theorem lt_iff_ssubset {s₁ s₂ : finset α} : s₁ < s₂ ↔ s₁ ⊂ s₂ := iff.rfl @[simp] lemma coe_ssubset {s₁ s₂ : finset α} : (↑s₁ : set α) ⊂ ↑s₂ ↔ s₁ ⊂ s₂ := show (↑s₁ : set α) ⊂ ↑s₂ ↔ s₁ ⊆ s₂ ∧ ¬s₂ ⊆ s₁, by simp only [set.ssubset_def, finset.coe_subset] @[simp] theorem val_lt_iff {s₁ s₂ : finset α} : s₁.1 < s₂.1 ↔ s₁ ⊂ s₂ := and_congr val_le_iff $ not_congr val_le_iff /-! ### Nonempty -/ /-- The property `s.nonempty` expresses the fact that the finset `s` is not empty. It should be used in theorem assumptions instead of `∃ x, x ∈ s` or `s ≠ ∅` as it gives access to a nice API thanks to the dot notation. -/ protected def nonempty (s : finset α) : Prop := ∃ x:α, x ∈ s @[elim_cast] lemma coe_nonempty {s : finset α} : (↑s:set α).nonempty ↔ s.nonempty := iff.rfl lemma nonempty.bex {s : finset α} (h : s.nonempty) : ∃ x:α, x ∈ s := h lemma nonempty.mono {s t : finset α} (hst : s ⊆ t) (hs : s.nonempty) : t.nonempty := set.nonempty.mono hst hs /-! ### empty -/ /-- The empty finset -/ protected def empty : finset α := ⟨0, nodup_zero⟩ instance : has_emptyc (finset α) := ⟨finset.empty⟩ instance : inhabited (finset α) := ⟨∅⟩ @[simp] theorem empty_val : (∅ : finset α).1 = 0 := rfl @[simp] theorem not_mem_empty (a : α) : a ∉ (∅ : finset α) := id @[simp] theorem ne_empty_of_mem {a : α} {s : finset α} (h : a ∈ s) : s ≠ ∅ | e := not_mem_empty a $ e ▸ h @[simp] theorem empty_subset (s : finset α) : ∅ ⊆ s := zero_subset _ theorem eq_empty_of_forall_not_mem {s : finset α} (H : ∀x, x ∉ s) : s = ∅ := eq_of_veq (eq_zero_of_forall_not_mem H) lemma eq_empty_iff_forall_not_mem {s : finset α} : s = ∅ ↔ ∀ x, x ∉ s := ⟨by rintro rfl x; exact id, λ h, eq_empty_of_forall_not_mem h⟩ @[simp] theorem val_eq_zero {s : finset α} : s.1 = 0 ↔ s = ∅ := @val_inj _ s ∅ theorem subset_empty {s : finset α} : s ⊆ ∅ ↔ s = ∅ := subset_zero.trans val_eq_zero theorem nonempty_of_ne_empty {s : finset α} (h : s ≠ ∅) : s.nonempty := exists_mem_of_ne_zero (mt val_eq_zero.1 h) theorem nonempty_iff_ne_empty {s : finset α} : s.nonempty ↔ s ≠ ∅ := ⟨λ ⟨a, ha⟩, ne_empty_of_mem ha, nonempty_of_ne_empty⟩ theorem eq_empty_or_nonempty (s : finset α) : s = ∅ ∨ s.nonempty := classical.by_cases or.inl (λ h, or.inr (nonempty_of_ne_empty h)) @[simp] lemma coe_empty : ↑(∅ : finset α) = (∅ : set α) := rfl /-- `finset.singleton a` is the set `{a}` containing `a` and nothing else. This differs from `singleton a` in that it does not require a `decidable_eq` instance for `α`. -/ def singleton (a : α) : finset α := ⟨_, nodup_singleton a⟩ local prefix `ι`:90 := singleton @[simp] theorem singleton_val (a : α) : (ι a).1 = a :: 0 := rfl @[simp] theorem mem_singleton {a b : α} : b ∈ ι a ↔ b = a := mem_singleton theorem not_mem_singleton {a b : α} : a ∉ ι b ↔ a ≠ b := not_iff_not_of_iff mem_singleton theorem mem_singleton_self (a : α) : a ∈ ι a := or.inl rfl theorem singleton_inj {a b : α} : ι a = ι b ↔ a = b := ⟨λ h, mem_singleton.1 (h ▸ mem_singleton_self _), congr_arg _⟩ @[simp] theorem singleton_ne_empty (a : α) : ι a ≠ ∅ := ne_empty_of_mem (mem_singleton_self _) @[simp] lemma coe_singleton (a : α) : ↑(ι a) = ({a} : set α) := rfl lemma eq_singleton_iff_unique_mem {s : finset α} {a : α} : s = finset.singleton a ↔ a ∈ s ∧ ∀ x ∈ s, x = a := begin split; intro t, rw t, refine ⟨finset.mem_singleton_self _, λ _, finset.mem_singleton.1⟩, ext, rw finset.mem_singleton, refine ⟨t.right _, λ r, r.symm ▸ t.left⟩ end lemma singleton_iff_unique_mem (s : finset α) : (∃ a, s = finset.singleton a) ↔ ∃! a, a ∈ s := by simp only [eq_singleton_iff_unique_mem, exists_unique] @[simp] lemma singleton_subset_iff {s : finset α} {a : α} : singleton a ⊆ s ↔ a ∈ s := set.singleton_subset_iff /-! ### insert -/ section decidable_eq variables [decidable_eq α] /-- `insert a s` is the set `{a} ∪ s` containing `a` and the elements of `s`. -/ instance : has_insert α (finset α) := ⟨λ a s, ⟨_, nodup_ndinsert a s.2⟩⟩ theorem insert_def (a : α) (s : finset α) : insert a s = ⟨_, nodup_ndinsert a s.2⟩ := rfl @[simp] theorem insert_val (a : α) (s : finset α) : (insert a s).1 = ndinsert a s.1 := rfl theorem insert_val' (a : α) (s : finset α) : (insert a s).1 = erase_dup (a :: s.1) := by rw [erase_dup_cons, erase_dup_eq_self]; refl theorem insert_val_of_not_mem {a : α} {s : finset α} (h : a ∉ s) : (insert a s).1 = a :: s.1 := by rw [insert_val, ndinsert_of_not_mem h] @[simp] theorem mem_insert {a b : α} {s : finset α} : a ∈ insert b s ↔ a = b ∨ a ∈ s := mem_ndinsert theorem mem_insert_self (a : α) (s : finset α) : a ∈ insert a s := mem_ndinsert_self a s.1 theorem mem_insert_of_mem {a b : α} {s : finset α} (h : a ∈ s) : a ∈ insert b s := mem_ndinsert_of_mem h theorem mem_of_mem_insert_of_ne {a b : α} {s : finset α} (h : b ∈ insert a s) : b ≠ a → b ∈ s := (mem_insert.1 h).resolve_left @[simp] lemma coe_insert (a : α) (s : finset α) : ↑(insert a s) = (insert a ↑s : set α) := set.ext $ λ x, by simp only [mem_coe, mem_insert, set.mem_insert_iff] @[simp] theorem insert_eq_of_mem {a : α} {s : finset α} (h : a ∈ s) : insert a s = s := eq_of_veq $ ndinsert_of_mem h theorem insert.comm (a b : α) (s : finset α) : insert a (insert b s) = insert b (insert a s) := ext.2 $ λ x, by simp only [finset.mem_insert, or.left_comm] @[simp] theorem insert_idem (a : α) (s : finset α) : insert a (insert a s) = insert a s := ext.2 $ λ x, by simp only [finset.mem_insert, or.assoc.symm, or_self] @[simp] theorem insert_ne_empty (a : α) (s : finset α) : insert a s ≠ ∅ := ne_empty_of_mem (mem_insert_self a s) lemma ne_insert_of_not_mem (s t : finset α) {a : α} (h : a ∉ s) : s ≠ insert a t := by { contrapose! h, simp [h] } theorem insert_subset {a : α} {s t : finset α} : insert a s ⊆ t ↔ a ∈ t ∧ s ⊆ t := by simp only [subset_iff, mem_insert, forall_eq, or_imp_distrib, forall_and_distrib] theorem subset_insert (a : α) (s : finset α) : s ⊆ insert a s := λ b, mem_insert_of_mem theorem insert_subset_insert (a : α) {s t : finset α} (h : s ⊆ t) : insert a s ⊆ insert a t := insert_subset.2 ⟨mem_insert_self _ _, subset.trans h (subset_insert _ _)⟩ lemma ssubset_iff {s t : finset α} : s ⊂ t ↔ (∃a, a ∉ s ∧ insert a s ⊆ t) := iff.intro (assume ⟨h₁, h₂⟩, have ∃a ∈ t, a ∉ s, by simpa only [finset.subset_iff, classical.not_forall] using h₂, let ⟨a, hat, has⟩ := this in ⟨a, has, insert_subset.mpr ⟨hat, h₁⟩⟩) (assume ⟨a, hat, has⟩, let ⟨h₁, h₂⟩ := insert_subset.mp has in ⟨h₂, assume h, hat $ h h₁⟩) lemma ssubset_insert {s : finset α} {a : α} (h : a ∉ s) : s ⊂ insert a s := ssubset_iff.mpr ⟨a, h, subset.refl _⟩ @[recursor 6] protected theorem induction {α : Type*} {p : finset α → Prop} [decidable_eq α] (h₁ : p ∅) (h₂ : ∀ ⦃a : α⦄ {s : finset α}, a ∉ s → p s → p (insert a s)) : ∀ s, p s | ⟨s, nd⟩ := multiset.induction_on s (λ _, h₁) (λ a s IH nd, begin cases nodup_cons.1 nd with m nd', rw [← (eq_of_veq _ : insert a (finset.mk s _) = ⟨a::s, nd⟩)], { exact h₂ (by exact m) (IH nd') }, { rw [insert_val, ndinsert_of_not_mem m] } end) nd /-- To prove a proposition about an arbitrary `finset α`, it suffices to prove it for the empty `finset`, and to show that if it holds for some `finset α`, then it holds for the `finset` obtained by inserting a new element. -/ @[elab_as_eliminator] protected theorem induction_on {α : Type*} {p : finset α → Prop} [decidable_eq α] (s : finset α) (h₁ : p ∅) (h₂ : ∀ ⦃a : α⦄ {s : finset α}, a ∉ s → p s → p (insert a s)) : p s := finset.induction h₁ h₂ s @[simp] theorem singleton_eq_singleton (a : α) : {a} = ι a := rfl theorem insert_empty_eq_singleton (a : α) : {a} = ι a := rfl theorem insert_singleton_self_eq (a : α) : ({a, a} : finset α) = ι a := insert_eq_of_mem $ mem_singleton_self _ @[simp] theorem insert_singleton_self_eq' {a : α} : insert a (ι a) = ι a := insert_singleton_self_eq _ /-! ### union -/ /-- `s ∪ t` is the set such that `a ∈ s ∪ t` iff `a ∈ s` or `a ∈ t`. -/ instance : has_union (finset α) := ⟨λ s₁ s₂, ⟨_, nodup_ndunion s₁.1 s₂.2⟩⟩ theorem union_val_nd (s₁ s₂ : finset α) : (s₁ ∪ s₂).1 = ndunion s₁.1 s₂.1 := rfl @[simp] theorem union_val (s₁ s₂ : finset α) : (s₁ ∪ s₂).1 = s₁.1 ∪ s₂.1 := ndunion_eq_union s₁.2 @[simp] theorem mem_union {a : α} {s₁ s₂ : finset α} : a ∈ s₁ ∪ s₂ ↔ a ∈ s₁ ∨ a ∈ s₂ := mem_ndunion theorem mem_union_left {a : α} {s₁ : finset α} (s₂ : finset α) (h : a ∈ s₁) : a ∈ s₁ ∪ s₂ := mem_union.2 $ or.inl h theorem mem_union_right {a : α} {s₂ : finset α} (s₁ : finset α) (h : a ∈ s₂) : a ∈ s₁ ∪ s₂ := mem_union.2 $ or.inr h theorem not_mem_union {a : α} {s₁ s₂ : finset α} : a ∉ s₁ ∪ s₂ ↔ a ∉ s₁ ∧ a ∉ s₂ := by rw [mem_union, not_or_distrib] @[simp] lemma coe_union (s₁ s₂ : finset α) : ↑(s₁ ∪ s₂) = (↑s₁ ∪ ↑s₂ : set α) := set.ext $ λ x, mem_union theorem union_subset {s₁ s₂ s₃ : finset α} (h₁ : s₁ ⊆ s₃) (h₂ : s₂ ⊆ s₃) : s₁ ∪ s₂ ⊆ s₃ := val_le_iff.1 (ndunion_le.2 ⟨h₁, val_le_iff.2 h₂⟩) theorem subset_union_left (s₁ s₂ : finset α) : s₁ ⊆ s₁ ∪ s₂ := λ x, mem_union_left _ theorem subset_union_right (s₁ s₂ : finset α) : s₂ ⊆ s₁ ∪ s₂ := λ x, mem_union_right _ theorem union_comm (s₁ s₂ : finset α) : s₁ ∪ s₂ = s₂ ∪ s₁ := ext.2 $ λ x, by simp only [mem_union, or_comm] instance : is_commutative (finset α) (∪) := ⟨union_comm⟩ @[simp] theorem union_assoc (s₁ s₂ s₃ : finset α) : (s₁ ∪ s₂) ∪ s₃ = s₁ ∪ (s₂ ∪ s₃) := ext.2 $ λ x, by simp only [mem_union, or_assoc] instance : is_associative (finset α) (∪) := ⟨union_assoc⟩ @[simp] theorem union_idempotent (s : finset α) : s ∪ s = s := ext.2 $ λ _, mem_union.trans $ or_self _ instance : is_idempotent (finset α) (∪) := ⟨union_idempotent⟩ theorem union_left_comm (s₁ s₂ s₃ : finset α) : s₁ ∪ (s₂ ∪ s₃) = s₂ ∪ (s₁ ∪ s₃) := ext.2 $ λ _, by simp only [mem_union, or.left_comm] theorem union_right_comm (s₁ s₂ s₃ : finset α) : (s₁ ∪ s₂) ∪ s₃ = (s₁ ∪ s₃) ∪ s₂ := ext.2 $ λ x, by simp only [mem_union, or_assoc, or_comm (x ∈ s₂)] theorem union_self (s : finset α) : s ∪ s = s := union_idempotent s @[simp] theorem union_empty (s : finset α) : s ∪ ∅ = s := ext.2 $ λ x, mem_union.trans $ or_false _ @[simp] theorem empty_union (s : finset α) : ∅ ∪ s = s := ext.2 $ λ x, mem_union.trans $ false_or _ theorem insert_eq (a : α) (s : finset α) : insert a s = {a} ∪ s := rfl @[simp] theorem insert_union (a : α) (s t : finset α) : insert a s ∪ t = insert a (s ∪ t) := by simp only [insert_eq, union_assoc] @[simp] theorem union_insert (a : α) (s t : finset α) : s ∪ insert a t = insert a (s ∪ t) := by simp only [insert_eq, union_left_comm] theorem insert_union_distrib (a : α) (s t : finset α) : insert a (s ∪ t) = insert a s ∪ insert a t := by simp only [insert_union, union_insert, insert_idem] @[simp] lemma union_eq_left_iff_subset {s t : finset α} : s ∪ t = s ↔ t ⊆ s := begin split, { assume h, have : t ⊆ s ∪ t := subset_union_right _ _, rwa h at this }, { assume h, exact subset.antisymm (union_subset (subset.refl _) h) (subset_union_left _ _) } end @[simp] lemma left_eq_union_iff_subset {s t : finset α} : s = s ∪ t ↔ t ⊆ s := by rw [← union_eq_left_iff_subset, eq_comm] @[simp] lemma union_eq_right_iff_subset {s t : finset α} : t ∪ s = s ↔ t ⊆ s := by rw [union_comm, union_eq_left_iff_subset] @[simp] lemma right_eq_union_iff_subset {s t : finset α} : s = t ∪ s ↔ t ⊆ s := by rw [← union_eq_right_iff_subset, eq_comm] /-! ### inter -/ /-- `s ∩ t` is the set such that `a ∈ s ∩ t` iff `a ∈ s` and `a ∈ t`. -/ instance : has_inter (finset α) := ⟨λ s₁ s₂, ⟨_, nodup_ndinter s₂.1 s₁.2⟩⟩ theorem inter_val_nd (s₁ s₂ : finset α) : (s₁ ∩ s₂).1 = ndinter s₁.1 s₂.1 := rfl @[simp] theorem inter_val (s₁ s₂ : finset α) : (s₁ ∩ s₂).1 = s₁.1 ∩ s₂.1 := ndinter_eq_inter s₁.2 @[simp] theorem mem_inter {a : α} {s₁ s₂ : finset α} : a ∈ s₁ ∩ s₂ ↔ a ∈ s₁ ∧ a ∈ s₂ := mem_ndinter theorem mem_of_mem_inter_left {a : α} {s₁ s₂ : finset α} (h : a ∈ s₁ ∩ s₂) : a ∈ s₁ := (mem_inter.1 h).1 theorem mem_of_mem_inter_right {a : α} {s₁ s₂ : finset α} (h : a ∈ s₁ ∩ s₂) : a ∈ s₂ := (mem_inter.1 h).2 theorem mem_inter_of_mem {a : α} {s₁ s₂ : finset α} : a ∈ s₁ → a ∈ s₂ → a ∈ s₁ ∩ s₂ := and_imp.1 mem_inter.2 theorem inter_subset_left (s₁ s₂ : finset α) : s₁ ∩ s₂ ⊆ s₁ := λ a, mem_of_mem_inter_left theorem inter_subset_right (s₁ s₂ : finset α) : s₁ ∩ s₂ ⊆ s₂ := λ a, mem_of_mem_inter_right theorem subset_inter {s₁ s₂ s₃ : finset α} : s₁ ⊆ s₂ → s₁ ⊆ s₃ → s₁ ⊆ s₂ ∩ s₃ := by simp only [subset_iff, mem_inter] {contextual:=tt}; intros; split; trivial @[simp] lemma coe_inter (s₁ s₂ : finset α) : ↑(s₁ ∩ s₂) = (↑s₁ ∩ ↑s₂ : set α) := set.ext $ λ _, mem_inter @[simp] theorem union_inter_cancel_left {s t : finset α} : (s ∪ t) ∩ s = s := by rw [← coe_inj, coe_inter, coe_union, set.union_inter_cancel_left] @[simp] theorem union_inter_cancel_right {s t : finset α} : (s ∪ t) ∩ t = t := by rw [← coe_inj, coe_inter, coe_union, set.union_inter_cancel_right] theorem inter_comm (s₁ s₂ : finset α) : s₁ ∩ s₂ = s₂ ∩ s₁ := ext.2 $ λ _, by simp only [mem_inter, and_comm] @[simp] theorem inter_assoc (s₁ s₂ s₃ : finset α) : (s₁ ∩ s₂) ∩ s₃ = s₁ ∩ (s₂ ∩ s₃) := ext.2 $ λ _, by simp only [mem_inter, and_assoc] theorem inter_left_comm (s₁ s₂ s₃ : finset α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) := ext.2 $ λ _, by simp only [mem_inter, and.left_comm] theorem inter_right_comm (s₁ s₂ s₃ : finset α) : (s₁ ∩ s₂) ∩ s₃ = (s₁ ∩ s₃) ∩ s₂ := ext.2 $ λ _, by simp only [mem_inter, and.right_comm] @[simp] theorem inter_self (s : finset α) : s ∩ s = s := ext.2 $ λ _, mem_inter.trans $ and_self _ @[simp] theorem inter_empty (s : finset α) : s ∩ ∅ = ∅ := ext.2 $ λ _, mem_inter.trans $ and_false _ @[simp] theorem empty_inter (s : finset α) : ∅ ∩ s = ∅ := ext.2 $ λ _, mem_inter.trans $ false_and _ @[simp] theorem insert_inter_of_mem {s₁ s₂ : finset α} {a : α} (h : a ∈ s₂) : insert a s₁ ∩ s₂ = insert a (s₁ ∩ s₂) := ext.2 $ λ x, have x = a ∨ x ∈ s₂ ↔ x ∈ s₂, from or_iff_right_of_imp $ by rintro rfl; exact h, by simp only [mem_inter, mem_insert, or_and_distrib_left, this] @[simp] theorem inter_insert_of_mem {s₁ s₂ : finset α} {a : α} (h : a ∈ s₁) : s₁ ∩ insert a s₂ = insert a (s₁ ∩ s₂) := by rw [inter_comm, insert_inter_of_mem h, inter_comm] @[simp] theorem insert_inter_of_not_mem {s₁ s₂ : finset α} {a : α} (h : a ∉ s₂) : insert a s₁ ∩ s₂ = s₁ ∩ s₂ := ext.2 $ λ x, have ¬ (x = a ∧ x ∈ s₂), by rintro ⟨rfl, H⟩; exact h H, by simp only [mem_inter, mem_insert, or_and_distrib_right, this, false_or] @[simp] theorem inter_insert_of_not_mem {s₁ s₂ : finset α} {a : α} (h : a ∉ s₁) : s₁ ∩ insert a s₂ = s₁ ∩ s₂ := by rw [inter_comm, insert_inter_of_not_mem h, inter_comm] @[simp] theorem singleton_inter_of_mem {a : α} {s : finset α} (H : a ∈ s) : ι a ∩ s = ι a := show insert a ∅ ∩ s = insert a ∅, by rw [insert_inter_of_mem H, empty_inter] @[simp] theorem singleton_inter_of_not_mem {a : α} {s : finset α} (H : a ∉ s) : ι a ∩ s = ∅ := eq_empty_of_forall_not_mem $ by simp only [mem_inter, mem_singleton]; rintro x ⟨rfl, h⟩; exact H h @[simp] theorem inter_singleton_of_mem {a : α} {s : finset α} (h : a ∈ s) : s ∩ ι a = ι a := by rw [inter_comm, singleton_inter_of_mem h] @[simp] theorem inter_singleton_of_not_mem {a : α} {s : finset α} (h : a ∉ s) : s ∩ ι a = ∅ := by rw [inter_comm, singleton_inter_of_not_mem h] @[mono] lemma inter_subset_inter {x y s t : finset α} (h : x ⊆ y) (h' : s ⊆ t) : x ∩ s ⊆ y ∩ t := begin intros a a_in, rw finset.mem_inter at a_in ⊢, exact ⟨h a_in.1, h' a_in.2⟩ end lemma inter_subset_inter_right {x y s : finset α} (h : x ⊆ y) : x ∩ s ⊆ y ∩ s := finset.inter_subset_inter h (finset.subset.refl _) lemma inter_subset_inter_left {x y s : finset α} (h : x ⊆ y) : s ∩ x ⊆ s ∩ y := finset.inter_subset_inter (finset.subset.refl _) h /-! ### lattice laws -/ instance : lattice (finset α) := { sup := (∪), sup_le := assume a b c, union_subset, le_sup_left := subset_union_left, le_sup_right := subset_union_right, inf := (∩), le_inf := assume a b c, subset_inter, inf_le_left := inter_subset_left, inf_le_right := inter_subset_right, ..finset.partial_order } @[simp] theorem sup_eq_union (s t : finset α) : s ⊔ t = s ∪ t := rfl @[simp] theorem inf_eq_inter (s t : finset α) : s ⊓ t = s ∩ t := rfl instance : semilattice_inf_bot (finset α) := { bot := ∅, bot_le := empty_subset, ..finset.lattice } instance {α : Type*} [decidable_eq α] : semilattice_sup_bot (finset α) := { ..finset.semilattice_inf_bot, ..finset.lattice } instance : distrib_lattice (finset α) := { le_sup_inf := assume a b c, show (a ∪ b) ∩ (a ∪ c) ⊆ a ∪ b ∩ c, by simp only [subset_iff, mem_inter, mem_union, and_imp, or_imp_distrib] {contextual:=tt}; simp only [true_or, imp_true_iff, true_and, or_true], ..finset.lattice } theorem inter_distrib_left (s t u : finset α) : s ∩ (t ∪ u) = (s ∩ t) ∪ (s ∩ u) := inf_sup_left theorem inter_distrib_right (s t u : finset α) : (s ∪ t) ∩ u = (s ∩ u) ∪ (t ∩ u) := inf_sup_right theorem union_distrib_left (s t u : finset α) : s ∪ (t ∩ u) = (s ∪ t) ∩ (s ∪ u) := sup_inf_left theorem union_distrib_right (s t u : finset α) : (s ∩ t) ∪ u = (s ∪ u) ∩ (t ∪ u) := sup_inf_right /-! ### erase -/ /-- `erase s a` is the set `s - {a}`, that is, the elements of `s` which are not equal to `a`. -/ def erase (s : finset α) (a : α) : finset α := ⟨_, nodup_erase_of_nodup a s.2⟩ @[simp] theorem erase_val (s : finset α) (a : α) : (erase s a).1 = s.1.erase a := rfl @[simp] theorem mem_erase {a b : α} {s : finset α} : a ∈ erase s b ↔ a ≠ b ∧ a ∈ s := mem_erase_iff_of_nodup s.2 theorem not_mem_erase (a : α) (s : finset α) : a ∉ erase s a := mem_erase_of_nodup s.2 @[simp] theorem erase_empty (a : α) : erase ∅ a = ∅ := rfl theorem ne_of_mem_erase {a b : α} {s : finset α} : b ∈ erase s a → b ≠ a := by simp only [mem_erase]; exact and.left theorem mem_of_mem_erase {a b : α} {s : finset α} : b ∈ erase s a → b ∈ s := mem_of_mem_erase theorem mem_erase_of_ne_of_mem {a b : α} {s : finset α} : a ≠ b → a ∈ s → a ∈ erase s b := by simp only [mem_erase]; exact and.intro theorem erase_insert {a : α} {s : finset α} (h : a ∉ s) : erase (insert a s) a = s := ext.2 $ assume x, by simp only [mem_erase, mem_insert, and_or_distrib_left, not_and_self, false_or]; apply and_iff_right_of_imp; rintro H rfl; exact h H theorem insert_erase {a : α} {s : finset α} (h : a ∈ s) : insert a (erase s a) = s := ext.2 $ assume x, by simp only [mem_insert, mem_erase, or_and_distrib_left, dec_em, true_and]; apply or_iff_right_of_imp; rintro rfl; exact h theorem erase_subset_erase (a : α) {s t : finset α} (h : s ⊆ t) : erase s a ⊆ erase t a := val_le_iff.1 $ erase_le_erase _ $ val_le_iff.2 h theorem erase_subset (a : α) (s : finset α) : erase s a ⊆ s := erase_subset _ _ @[simp] lemma coe_erase (a : α) (s : finset α) : ↑(erase s a) = (↑s \ {a} : set α) := set.ext $ λ _, mem_erase.trans $ by rw [and_comm, set.mem_diff, set.mem_singleton_iff]; refl lemma erase_ssubset {a : α} {s : finset α} (h : a ∈ s) : s.erase a ⊂ s := calc s.erase a ⊂ insert a (s.erase a) : ssubset_insert $ not_mem_erase _ _ ... = _ : insert_erase h theorem erase_eq_of_not_mem {a : α} {s : finset α} (h : a ∉ s) : erase s a = s := eq_of_veq $ erase_of_not_mem h theorem subset_insert_iff {a : α} {s t : finset α} : s ⊆ insert a t ↔ erase s a ⊆ t := by simp only [subset_iff, or_iff_not_imp_left, mem_erase, mem_insert, and_imp]; exact forall_congr (λ x, forall_swap) theorem erase_insert_subset (a : α) (s : finset α) : erase (insert a s) a ⊆ s := subset_insert_iff.1 $ subset.refl _ theorem insert_erase_subset (a : α) (s : finset α) : s ⊆ insert a (erase s a) := subset_insert_iff.2 $ subset.refl _ /-! ### sdiff -/ /-- `s \ t` is the set consisting of the elements of `s` that are not in `t`. -/ instance : has_sdiff (finset α) := ⟨λs₁ s₂, ⟨s₁.1 - s₂.1, nodup_of_le (sub_le_self _ _) s₁.2⟩⟩ @[simp] theorem mem_sdiff {a : α} {s₁ s₂ : finset α} : a ∈ s₁ \ s₂ ↔ a ∈ s₁ ∧ a ∉ s₂ := mem_sub_of_nodup s₁.2 theorem sdiff_union_of_subset {s₁ s₂ : finset α} (h : s₁ ⊆ s₂) : (s₂ \ s₁) ∪ s₁ = s₂ := ext.2 $ λ a, by simpa only [mem_sdiff, mem_union, or_comm, or_and_distrib_left, dec_em, and_true] using or_iff_right_of_imp (@h a) theorem union_sdiff_of_subset {s₁ s₂ : finset α} (h : s₁ ⊆ s₂) : s₁ ∪ (s₂ \ s₁) = s₂ := (union_comm _ _).trans (sdiff_union_of_subset h) theorem inter_sdiff (s t u : finset α) : s ∩ (t \ u) = s ∩ t \ u := by { ext x, simp [and_assoc] } @[simp] theorem inter_sdiff_self (s₁ s₂ : finset α) : s₁ ∩ (s₂ \ s₁) = ∅ := eq_empty_of_forall_not_mem $ by simp only [mem_inter, mem_sdiff]; rintro x ⟨h, _, hn⟩; exact hn h @[simp] theorem sdiff_inter_self (s₁ s₂ : finset α) : (s₂ \ s₁) ∩ s₁ = ∅ := (inter_comm _ _).trans (inter_sdiff_self _ _) @[simp] theorem sdiff_self (s₁ : finset α) : s₁ \ s₁ = ∅ := by ext; simp theorem sdiff_inter_distrib_right (s₁ s₂ s₃ : finset α) : s₁ \ (s₂ ∩ s₃) = (s₁ \ s₂) ∪ (s₁ \ s₃) := by ext; simp only [and_or_distrib_left, mem_union, classical.not_and_distrib, mem_sdiff, mem_inter] @[simp] theorem sdiff_inter_self_left (s₁ s₂ : finset α) : s₁ \ (s₁ ∩ s₂) = s₁ \ s₂ := by simp only [sdiff_inter_distrib_right, sdiff_self, empty_union] @[simp] theorem sdiff_inter_self_right (s₁ s₂ : finset α) : s₁ \ (s₂ ∩ s₁) = s₁ \ s₂ := by simp only [sdiff_inter_distrib_right, sdiff_self, union_empty] @[simp] theorem sdiff_empty {s₁ : finset α} : s₁ \ ∅ = s₁ := ext.2 (by simp) @[mono] theorem sdiff_subset_sdiff {s₁ s₂ t₁ t₂ : finset α} (h₁ : t₁ ⊆ t₂) (h₂ : s₂ ⊆ s₁) : t₁ \ s₁ ⊆ t₂ \ s₂ := by simpa only [subset_iff, mem_sdiff, and_imp] using λ a m₁ m₂, and.intro (h₁ m₁) (mt (@h₂ _) m₂) theorem sdiff_subset_self {s₁ s₂ : finset α} : s₁ \ s₂ ⊆ s₁ := suffices s₁ \ s₂ ⊆ s₁ \ ∅, by simpa [sdiff_empty] using this, sdiff_subset_sdiff (subset.refl _) (empty_subset _) @[simp] lemma coe_sdiff (s₁ s₂ : finset α) : ↑(s₁ \ s₂) = (↑s₁ \ ↑s₂ : set α) := set.ext $ λ _, mem_sdiff @[simp] lemma to_set_sdiff (s t : finset α) : (s \ t).to_set = s.to_set \ t.to_set := by apply finset.coe_sdiff @[simp] theorem union_sdiff_self_eq_union {s t : finset α} : s ∪ (t \ s) = s ∪ t := ext.2 $ λ a, by simp only [mem_union, mem_sdiff, or_iff_not_imp_left, imp_and_distrib, and_iff_left id] @[simp] theorem sdiff_union_self_eq_union {s t : finset α} : (s \ t) ∪ t = s ∪ t := by rw [union_comm, union_sdiff_self_eq_union, union_comm] lemma union_sdiff_symm {s t : finset α} : s ∪ (t \ s) = t ∪ (s \ t) := by rw [union_sdiff_self_eq_union, union_sdiff_self_eq_union, union_comm] lemma sdiff_eq_empty_iff_subset {s t : finset α} : s \ t = ∅ ↔ s ⊆ t := by rw [subset_iff, ext]; simp @[simp] lemma empty_sdiff (s : finset α) : ∅ \ s = ∅ := by { rw sdiff_eq_empty_iff_subset, exact empty_subset _ } lemma insert_sdiff_of_not_mem (s : finset α) {t : finset α} {x : α} (h : x ∉ t) : (insert x s) \ t = insert x (s \ t) := begin rw [← coe_inj, coe_insert, coe_sdiff, coe_sdiff, coe_insert], exact set.insert_diff_of_not_mem ↑s h end lemma insert_sdiff_of_mem (s : finset α) {t : finset α} {x : α} (h : x ∈ t) : (insert x s) \ t = s \ t := begin rw [← coe_inj, coe_sdiff, coe_sdiff, coe_insert], exact set.insert_diff_of_mem ↑s h end @[simp] lemma sdiff_subset (s t : finset α) : s \ t ⊆ s := by simp [subset_iff, mem_sdiff] {contextual := tt} end decidable_eq /-! ### attach -/ /-- `attach s` takes the elements of `s` and forms a new set of elements of the subtype `{x // x ∈ s}`. -/ def attach (s : finset α) : finset {x // x ∈ s} := ⟨attach s.1, nodup_attach.2 s.2⟩ @[simp] theorem attach_val (s : finset α) : s.attach.1 = s.1.attach := rfl @[simp] theorem mem_attach (s : finset α) : ∀ x, x ∈ s.attach := mem_attach _ @[simp] theorem attach_empty : attach (∅ : finset α) = ∅ := rfl /-! ### piecewise -/ section piecewise /-- `s.piecewise f g` is the function equal to `f` on the finset `s`, and to `g` on its complement. -/ def piecewise {α : Type*} {δ : α → Sort*} (s : finset α) (f g : Πi, δ i) [∀j, decidable (j ∈ s)] : Πi, δ i := λi, if i ∈ s then f i else g i variables {δ : α → Sort*} (s : finset α) (f g : Πi, δ i) @[simp] lemma piecewise_insert_self [decidable_eq α] {j : α} [∀i, decidable (i ∈ insert j s)] : (insert j s).piecewise f g j = f j := by simp [piecewise] @[simp] lemma piecewise_empty [∀i : α, decidable (i ∈ (∅ : finset α))] : piecewise ∅ f g = g := by { ext i, simp [piecewise] } variable [∀j, decidable (j ∈ s)] @[elim_cast] lemma piecewise_coe [∀j, decidable (j ∈ (↑s : set α))] : (↑s : set α).piecewise f g = s.piecewise f g := by { ext, congr } @[simp, priority 980] lemma piecewise_eq_of_mem {i : α} (hi : i ∈ s) : s.piecewise f g i = f i := by simp [piecewise, hi] @[simp, priority 980] lemma piecewise_eq_of_not_mem {i : α} (hi : i ∉ s) : s.piecewise f g i = g i := by simp [piecewise, hi] @[simp, priority 990] lemma piecewise_insert_of_ne [decidable_eq α] {i j : α} [∀i, decidable (i ∈ insert j s)] (h : i ≠ j) : (insert j s).piecewise f g i = s.piecewise f g i := by { simp [piecewise, h], congr } lemma piecewise_insert [decidable_eq α] (j : α) [∀i, decidable (i ∈ insert j s)] : (insert j s).piecewise f g = function.update (s.piecewise f g) j (f j) := begin classical, rw [← piecewise_coe, ← piecewise_coe, ← set.piecewise_insert, ← coe_insert j s], congr end lemma update_eq_piecewise {β : Type*} [decidable_eq α] (f : α → β) (i : α) (v : β) : function.update f i v = piecewise (singleton i) (λj, v) f := begin ext j, by_cases h : j = i, { rw [h], simp }, { simp [h] } end end piecewise section decidable_pi_exists variables {s : finset α} instance decidable_dforall_finset {p : Πa∈s, Prop} [hp : ∀a (h : a ∈ s), decidable (p a h)] : decidable (∀a (h : a ∈ s), p a h) := multiset.decidable_dforall_multiset /-- decidable equality for functions whose domain is bounded by finsets -/ instance decidable_eq_pi_finset {β : α → Type*} [h : ∀a, decidable_eq (β a)] : decidable_eq (Πa∈s, β a) := multiset.decidable_eq_pi_multiset instance decidable_dexists_finset {p : Πa∈s, Prop} [hp : ∀a (h : a ∈ s), decidable (p a h)] : decidable (∃a (h : a ∈ s), p a h) := multiset.decidable_dexists_multiset end decidable_pi_exists /-! ### filter -/ section filter variables {p q : α → Prop} [decidable_pred p] [decidable_pred q] /-- `filter p s` is the set of elements of `s` that satisfy `p`. -/ def filter (p : α → Prop) [decidable_pred p] (s : finset α) : finset α := ⟨_, nodup_filter p s.2⟩ @[simp] theorem filter_val (s : finset α) : (filter p s).1 = s.1.filter p := rfl @[simp] theorem mem_filter {s : finset α} {a : α} : a ∈ s.filter p ↔ a ∈ s ∧ p a := mem_filter @[simp] theorem filter_subset (s : finset α) : s.filter p ⊆ s := filter_subset _ theorem filter_filter (s : finset α) : (s.filter p).filter q = s.filter (λa, p a ∧ q a) := ext.2 $ assume a, by simp only [mem_filter, and_comm, and.left_comm] @[simp] lemma filter_true {s : finset α} [h : decidable_pred (λ _, true)] : @finset.filter α (λ _, true) h s = s := by ext; simp @[simp] theorem filter_false {h} (s : finset α) : @filter α (λa, false) h s = ∅ := ext.2 $ assume a, by simp only [mem_filter, and_false]; refl lemma filter_congr {s : finset α} (H : ∀ x ∈ s, p x ↔ q x) : filter p s = filter q s := eq_of_veq $ filter_congr H lemma filter_empty : filter p ∅ = ∅ := subset_empty.1 $ filter_subset _ lemma filter_subset_filter {s t : finset α} (h : s ⊆ t) : s.filter p ⊆ t.filter p := assume a ha, mem_filter.2 ⟨h (mem_filter.1 ha).1, (mem_filter.1 ha).2⟩ @[simp] lemma coe_filter (s : finset α) : ↑(s.filter p) = ({x ∈ ↑s | p x} : set α) := set.ext $ λ _, mem_filter variable [decidable_eq α] theorem filter_union (s₁ s₂ : finset α) : (s₁ ∪ s₂).filter p = s₁.filter p ∪ s₂.filter p := ext.2 $ λ _, by simp only [mem_filter, mem_union, or_and_distrib_right] theorem filter_union_right (p q : α → Prop) [decidable_pred p] [decidable_pred q] (s : finset α) : s.filter p ∪ s.filter q = s.filter (λx, p x ∨ q x) := ext.2 $ λ x, by simp only [mem_filter, mem_union, and_or_distrib_left.symm] lemma filter_mem_eq_inter {s t : finset α} : s.filter (λ i, i ∈ t) = s ∩ t := ext' $ λ i, by rw [mem_filter, mem_inter] theorem filter_inter {s t : finset α} : filter p s ∩ t = filter p (s ∩ t) := by { ext, simp only [mem_inter, mem_filter, and.right_comm] } theorem inter_filter {s t : finset α} : s ∩ filter p t = filter p (s ∩ t) := by rw [inter_comm, filter_inter, inter_comm] theorem filter_insert (a : α) (s : finset α) : filter p (insert a s) = if p a then insert a (filter p s) else (filter p s) := by { ext x, simp, split_ifs with h; by_cases h' : x = a; simp [h, h'] } theorem filter_singleton (a : α) : filter p (singleton a) = if p a then singleton a else ∅ := by { ext x, simp, split_ifs with h; by_cases h' : x = a; simp [h, h'] } theorem filter_or (s : finset α) : s.filter (λ a, p a ∨ q a) = s.filter p ∪ s.filter q := ext.2 $ λ _, by simp only [mem_filter, mem_union, and_or_distrib_left] theorem filter_and (s : finset α) : s.filter (λ a, p a ∧ q a) = s.filter p ∩ s.filter q := ext.2 $ λ _, by simp only [mem_filter, mem_inter, and_comm, and.left_comm, and_self] theorem filter_not (s : finset α) : s.filter (λ a, ¬ p a) = s \ s.filter p := ext.2 $ by simpa only [mem_filter, mem_sdiff, and_comm, not_and] using λ a, and_congr_right $ λ h : a ∈ s, (imp_iff_right h).symm.trans imp_not_comm theorem sdiff_eq_filter (s₁ s₂ : finset α) : s₁ \ s₂ = filter (∉ s₂) s₁ := ext.2 $ λ _, by simp only [mem_sdiff, mem_filter] theorem sdiff_eq_self (s₁ s₂ : finset α) : s₁ \ s₂ = s₁ ↔ s₁ ∩ s₂ ⊆ ∅ := by { simp [subset.antisymm_iff,sdiff_subset_self], split; intro h, { transitivity' ((s₁ \ s₂) ∩ s₂), mono, simp }, { calc s₁ \ s₂ ⊇ s₁ \ (s₁ ∩ s₂) : by simp [(⊇)] ... ⊇ s₁ \ ∅ : by mono using [(⊇)] ... ⊇ s₁ : by simp [(⊇)] } } theorem filter_union_filter_neg_eq (s : finset α) : s.filter p ∪ s.filter (λa, ¬ p a) = s := by simp only [filter_not, union_sdiff_of_subset (filter_subset s)] theorem filter_inter_filter_neg_eq (s : finset α) : s.filter p ∩ s.filter (λa, ¬ p a) = ∅ := by simp only [filter_not, inter_sdiff_self] lemma subset_union_elim {s : finset α} {t₁ t₂ : set α} [decidable_pred (∈ t₁)] (h : ↑s ⊆ t₁ ∪ t₂) : ∃s₁ s₂ : finset α, s₁ ∪ s₂ = s ∧ ↑s₁ ⊆ t₁ ∧ ↑s₂ ⊆ t₂ \ t₁ := begin refine ⟨s.filter (∈ t₁), s.filter (∉ t₁), _, _ , _⟩, { simp [filter_union_right, classical.or_not] }, { intro x, simp }, { intro x, simp, intros hx hx₂, refine ⟨or.resolve_left (h hx) hx₂, hx₂⟩ } end /- We can simplify an application of filter where the decidability is inferred in "the wrong way" -/ @[simp] lemma filter_congr_decidable {α} (s : finset α) (p : α → Prop) (h : decidable_pred p) [decidable_pred p] : @filter α p h s = s.filter p := by congr section classical open_locale classical /-- The following instance allows us to write `{ x ∈ s | p x }` for `finset.filter s p`. Since the former notation requires us to define this for all propositions `p`, and `finset.filter` only works for decidable propositions, the notation `{ x ∈ s | p x }` is only compatible with classical logic because it uses `classical.prop_decidable`. We don't want to redo all lemmas of `finset.filter` for `has_sep.sep`, so we make sure that `simp` unfolds the notation `{ x ∈ s | p x }` to `finset.filter s p`. If `p` happens to be decidable, the simp-lemma `filter_congr_decidable` will make sure that `finset.filter` uses the right instance for decidability. -/ noncomputable instance {α : Type*} : has_sep α (finset α) := ⟨λ p x, x.filter p⟩ @[simp] lemma sep_def {α : Type*} (s : finset α) (p : α → Prop) : {x ∈ s | p x} = s.filter p := rfl end classical /-- After filtering out everything that does not equal a given value, at most that value remains. This is equivalent to `filter_eq'` with the equality the other way. -/ -- This is not a good simp lemma, as it would prevent `finset.mem_filter` from firing -- on, e.g. `x ∈ s.filter(eq b)`. lemma filter_eq [decidable_eq β] (s : finset β) (b : β) : s.filter(eq b) = ite (b ∈ s) {b} ∅ := begin split_ifs, { ext, simp only [mem_filter, insert_empty_eq_singleton, mem_singleton], exact ⟨λ h, h.2.symm, by { rintro ⟨h⟩, exact ⟨h, rfl⟩, }⟩ }, { ext, simp only [mem_filter, not_and, iff_false, not_mem_empty], rintros m ⟨e⟩, exact h m, } end /-- After filtering out everything that does not equal a given value, at most that value remains. This is equivalent to `filter_eq` with the equality the other way. -/ lemma filter_eq' [decidable_eq β] (s : finset β) (b : β) : s.filter (λ a, a = b) = ite (b ∈ s) {b} ∅ := trans (filter_congr (λ _ _, ⟨eq.symm, eq.symm⟩)) (filter_eq s b) end filter /-! ### range -/ section range variables {n m l : ℕ} /-- `range n` is the set of natural numbers less than `n`. -/ def range (n : ℕ) : finset ℕ := ⟨_, nodup_range n⟩ @[simp] theorem range_val (n : ℕ) : (range n).1 = multiset.range n := rfl @[simp] theorem mem_range : m ∈ range n ↔ m < n := mem_range @[simp] theorem range_zero : range 0 = ∅ := rfl @[simp] theorem range_one : range 1 = {0} := rfl theorem range_succ : range (succ n) = insert n (range n) := eq_of_veq $ (range_succ n).trans $ (ndinsert_of_not_mem not_mem_range_self).symm theorem range_add_one : range (n + 1) = insert n (range n) := range_succ @[simp] theorem not_mem_range_self : n ∉ range n := not_mem_range_self @[simp] theorem range_subset {n m} : range n ⊆ range m ↔ n ≤ m := range_subset theorem range_mono : monotone range := λ _ _, range_subset.2 end range /- useful rules for calculations with quantifiers -/ theorem exists_mem_empty_iff (p : α → Prop) : (∃ x, x ∈ (∅ : finset α) ∧ p x) ↔ false := by simp only [not_mem_empty, false_and, exists_false] theorem exists_mem_insert [d : decidable_eq α] (a : α) (s : finset α) (p : α → Prop) : (∃ x, x ∈ insert a s ∧ p x) ↔ p a ∨ (∃ x, x ∈ s ∧ p x) := by simp only [mem_insert, or_and_distrib_right, exists_or_distrib, exists_eq_left] theorem forall_mem_empty_iff (p : α → Prop) : (∀ x, x ∈ (∅ : finset α) → p x) ↔ true := iff_true_intro $ λ _, false.elim theorem forall_mem_insert [d : decidable_eq α] (a : α) (s : finset α) (p : α → Prop) : (∀ x, x ∈ insert a s → p x) ↔ p a ∧ (∀ x, x ∈ s → p x) := by simp only [mem_insert, or_imp_distrib, forall_and_distrib, forall_eq] end finset namespace option /-- Construct an empty or singleton finset from an `option` -/ def to_finset (o : option α) : finset α := match o with | none := ∅ | some a := finset.singleton a end @[simp] theorem to_finset_none : none.to_finset = (∅ : finset α) := rfl @[simp] theorem to_finset_some {a : α} : (some a).to_finset = finset.singleton a := rfl @[simp] theorem mem_to_finset {a : α} {o : option α} : a ∈ o.to_finset ↔ a ∈ o := by cases o; simp only [to_finset, finset.mem_singleton, option.mem_def, eq_comm]; refl end option /-! ### erase_dup on list and multiset -/ namespace multiset variable [decidable_eq α] /-- `to_finset s` removes duplicates from the multiset `s` to produce a finset. -/ def to_finset (s : multiset α) : finset α := ⟨_, nodup_erase_dup s⟩ @[simp] theorem to_finset_val (s : multiset α) : s.to_finset.1 = s.erase_dup := rfl theorem to_finset_eq {s : multiset α} (n : nodup s) : finset.mk s n = s.to_finset := finset.val_inj.1 (erase_dup_eq_self.2 n).symm @[simp] theorem mem_to_finset {a : α} {s : multiset α} : a ∈ s.to_finset ↔ a ∈ s := mem_erase_dup @[simp] lemma to_finset_zero : to_finset (0 : multiset α) = ∅ := rfl @[simp] lemma to_finset_cons (a : α) (s : multiset α) : to_finset (a :: s) = insert a (to_finset s) := finset.eq_of_veq erase_dup_cons @[simp] lemma to_finset_add (s t : multiset α) : to_finset (s + t) = to_finset s ∪ to_finset t := finset.ext' $ by simp @[simp] lemma to_finset_smul (s : multiset α) : ∀(n : ℕ) (hn : n ≠ 0), (add_monoid.smul n s).to_finset = s.to_finset | 0 h := by contradiction | (n+1) h := begin by_cases n = 0, { rw [h, zero_add, add_monoid.one_smul] }, { rw [add_monoid.add_smul, to_finset_add, add_monoid.one_smul, to_finset_smul n h, finset.union_idempotent] } end @[simp] lemma to_finset_inter (s t : multiset α) : to_finset (s ∩ t) = to_finset s ∩ to_finset t := finset.ext' $ by simp theorem to_finset_eq_empty {m : multiset α} : m.to_finset = ∅ ↔ m = 0 := finset.val_inj.symm.trans multiset.erase_dup_eq_zero end multiset namespace list variable [decidable_eq α] /-- `to_finset l` removes duplicates from the list `l` to produce a finset. -/ def to_finset (l : list α) : finset α := multiset.to_finset l @[simp] theorem to_finset_val (l : list α) : l.to_finset.1 = (l.erase_dup : multiset α) := rfl theorem to_finset_eq {l : list α} (n : nodup l) : @finset.mk α l n = l.to_finset := multiset.to_finset_eq n @[simp] theorem mem_to_finset {a : α} {l : list α} : a ∈ l.to_finset ↔ a ∈ l := mem_erase_dup @[simp] theorem to_finset_nil : to_finset (@nil α) = ∅ := rfl @[simp] theorem to_finset_cons {a : α} {l : list α} : to_finset (a :: l) = insert a (to_finset l) := finset.eq_of_veq $ by by_cases h : a ∈ l; simp [finset.insert_val', multiset.erase_dup_cons, h] end list namespace finset /-! ### map -/ section map open function /-- When `f` is an embedding of `α` in `β` and `s` is a finset in `α`, then `s.map f` is the image finset in `β`. The embedding condition guarantees that there are no duplicates in the image. -/ def map (f : α ↪ β) (s : finset α) : finset β := ⟨s.1.map f, nodup_map f.2 s.2⟩ @[simp] theorem map_val (f : α ↪ β) (s : finset α) : (map f s).1 = s.1.map f := rfl @[simp] theorem map_empty (f : α ↪ β) : (∅ : finset α).map f = ∅ := rfl variables {f : α ↪ β} {s : finset α} @[simp] theorem mem_map {b : β} : b ∈ s.map f ↔ ∃ a ∈ s, f a = b := mem_map.trans $ by simp only [exists_prop]; refl theorem mem_map' (f : α ↪ β) {a} {s : finset α} : f a ∈ s.map f ↔ a ∈ s := mem_map_of_inj f.2 theorem mem_map_of_mem (f : α ↪ β) {a} {s : finset α} : a ∈ s → f a ∈ s.map f := (mem_map' _).2 theorem map_to_finset [decidable_eq α] [decidable_eq β] {s : multiset α} : s.to_finset.map f = (s.map f).to_finset := ext.2 $ λ _, by simp only [mem_map, multiset.mem_map, exists_prop, multiset.mem_to_finset] theorem map_refl : s.map (embedding.refl _) = s := ext.2 $ λ _, by simpa only [mem_map, exists_prop] using exists_eq_right theorem map_map {g : β ↪ γ} : (s.map f).map g = s.map (f.trans g) := eq_of_veq $ by simp only [map_val, multiset.map_map]; refl theorem map_subset_map {s₁ s₂ : finset α} : s₁.map f ⊆ s₂.map f ↔ s₁ ⊆ s₂ := ⟨λ h x xs, (mem_map' _).1 $ h $ (mem_map' f).2 xs, λ h, by simp [subset_def, map_subset_map h]⟩ theorem map_inj {s₁ s₂ : finset α} : s₁.map f = s₂.map f ↔ s₁ = s₂ := by simp only [subset.antisymm_iff, map_subset_map] /-- Associate to an embedding `f` from `α` to `β` the embedding that maps a finset to its image under `f`. -/ def map_embedding (f : α ↪ β) : finset α ↪ finset β := ⟨map f, λ s₁ s₂, map_inj.1⟩ @[simp] theorem map_embedding_apply : map_embedding f s = map f s := rfl theorem map_filter {p : β → Prop} [decidable_pred p] : (s.map f).filter p = (s.filter (p ∘ f)).map f := ext.2 $ λ b, by simp only [mem_filter, mem_map, exists_prop, and_assoc]; exact ⟨by rintro ⟨⟨x, h1, rfl⟩, h2⟩; exact ⟨x, h1, h2, rfl⟩, by rintro ⟨x, h1, h2, rfl⟩; exact ⟨⟨x, h1, rfl⟩, h2⟩⟩ theorem map_union [decidable_eq α] [decidable_eq β] {f : α ↪ β} (s₁ s₂ : finset α) : (s₁ ∪ s₂).map f = s₁.map f ∪ s₂.map f := ext.2 $ λ _, by simp only [mem_map, mem_union, exists_prop, or_and_distrib_right, exists_or_distrib] theorem map_inter [decidable_eq α] [decidable_eq β] {f : α ↪ β} (s₁ s₂ : finset α) : (s₁ ∩ s₂).map f = s₁.map f ∩ s₂.map f := ext.2 $ λ b, by simp only [mem_map, mem_inter, exists_prop]; exact ⟨by rintro ⟨a, ⟨m₁, m₂⟩, rfl⟩; exact ⟨⟨a, m₁, rfl⟩, ⟨a, m₂, rfl⟩⟩, by rintro ⟨⟨a, m₁, e⟩, ⟨a', m₂, rfl⟩⟩; cases f.2 e; exact ⟨_, ⟨m₁, m₂⟩, rfl⟩⟩ @[simp] theorem map_singleton (f : α ↪ β) (a : α) : (singleton a).map f = singleton (f a) := ext.2 $ λ _, by simp only [mem_map, mem_singleton, exists_prop, exists_eq_left]; exact eq_comm @[simp] theorem map_insert [decidable_eq α] [decidable_eq β] (f : α ↪ β) (a : α) (s : finset α) : (insert a s).map f = insert (f a) (s.map f) := by simp only [insert_eq, insert_empty_eq_singleton, map_union, map_singleton] @[simp] theorem map_eq_empty : s.map f = ∅ ↔ s = ∅ := ⟨λ h, eq_empty_of_forall_not_mem $ λ a m, ne_empty_of_mem (mem_map_of_mem _ m) h, λ e, e.symm ▸ rfl⟩ lemma attach_map_val {s : finset α} : s.attach.map (embedding.subtype _) = s := eq_of_veq $ by rw [map_val, attach_val]; exact attach_map_val _ end map lemma range_add_one' (n : ℕ) : range (n + 1) = insert 0 ((range n).map ⟨λi, i + 1, assume i j, nat.succ_inj⟩) := by ext (⟨⟩ | ⟨n⟩); simp [nat.succ_eq_add_one, nat.zero_lt_succ n] /-! ### image -/ section image variables [decidable_eq β] /-- `image f s` is the forward image of `s` under `f`. -/ def image (f : α → β) (s : finset α) : finset β := (s.1.map f).to_finset @[simp] theorem image_val (f : α → β) (s : finset α) : (image f s).1 = (s.1.map f).erase_dup := rfl @[simp] theorem image_empty (f : α → β) : (∅ : finset α).image f = ∅ := rfl variables {f : α → β} {s : finset α} @[simp] theorem mem_image {b : β} : b ∈ s.image f ↔ ∃ a ∈ s, f a = b := by simp only [mem_def, image_val, mem_erase_dup, multiset.mem_map, exists_prop] theorem mem_image_of_mem (f : α → β) {a} {s : finset α} (h : a ∈ s) : f a ∈ s.image f := mem_image.2 ⟨_, h, rfl⟩ @[simp] lemma coe_image {f : α → β} : ↑(s.image f) = f '' ↑s := set.ext $ λ _, mem_image.trans $ by simp only [exists_prop]; refl lemma nonempty.image (h : s.nonempty) (f : α → β) : (s.image f).nonempty := let ⟨a, ha⟩ := h in ⟨f a, mem_image_of_mem f ha⟩ theorem image_to_finset [decidable_eq α] {s : multiset α} : s.to_finset.image f = (s.map f).to_finset := ext.2 $ λ _, by simp only [mem_image, multiset.mem_to_finset, exists_prop, multiset.mem_map] theorem image_val_of_inj_on (H : ∀x∈s, ∀y∈s, f x = f y → x = y) : (image f s).1 = s.1.map f := multiset.erase_dup_eq_self.2 (nodup_map_on H s.2) theorem image_id [decidable_eq α] : s.image id = s := ext.2 $ λ _, by simp only [mem_image, exists_prop, id, exists_eq_right] theorem image_image [decidable_eq γ] {g : β → γ} : (s.image f).image g = s.image (g ∘ f) := eq_of_veq $ by simp only [image_val, erase_dup_map_erase_dup_eq, multiset.map_map] theorem image_subset_image {s₁ s₂ : finset α} (h : s₁ ⊆ s₂) : s₁.image f ⊆ s₂.image f := by simp only [subset_def, image_val, subset_erase_dup', erase_dup_subset', multiset.map_subset_map h] theorem image_mono (f : α → β) : monotone (finset.image f) := λ _ _, image_subset_image theorem image_filter {p : β → Prop} [decidable_pred p] : (s.image f).filter p = (s.filter (p ∘ f)).image f := ext.2 $ λ b, by simp only [mem_filter, mem_image, exists_prop]; exact ⟨by rintro ⟨⟨x, h1, rfl⟩, h2⟩; exact ⟨x, ⟨h1, h2⟩, rfl⟩, by rintro ⟨x, ⟨h1, h2⟩, rfl⟩; exact ⟨⟨x, h1, rfl⟩, h2⟩⟩ theorem image_union [decidable_eq α] {f : α → β} (s₁ s₂ : finset α) : (s₁ ∪ s₂).image f = s₁.image f ∪ s₂.image f := ext.2 $ λ _, by simp only [mem_image, mem_union, exists_prop, or_and_distrib_right, exists_or_distrib] theorem image_inter [decidable_eq α] (s₁ s₂ : finset α) (hf : ∀x y, f x = f y → x = y) : (s₁ ∩ s₂).image f = s₁.image f ∩ s₂.image f := ext.2 $ by simp only [mem_image, exists_prop, mem_inter]; exact λ b, ⟨λ ⟨a, ⟨m₁, m₂⟩, e⟩, ⟨⟨a, m₁, e⟩, ⟨a, m₂, e⟩⟩, λ ⟨⟨a, m₁, e₁⟩, ⟨a', m₂, e₂⟩⟩, ⟨a, ⟨m₁, hf _ _ (e₂.trans e₁.symm) ▸ m₂⟩, e₁⟩⟩. @[simp] theorem image_singleton (f : α → β) (a : α) : (singleton a).image f = singleton (f a) := ext.2 $ λ x, by simpa only [mem_image, exists_prop, mem_singleton, exists_eq_left] using eq_comm @[simp] theorem image_insert [decidable_eq α] (f : α → β) (a : α) (s : finset α) : (insert a s).image f = insert (f a) (s.image f) := by simp only [insert_eq, insert_empty_eq_singleton, image_singleton, image_union] @[simp] theorem image_eq_empty : s.image f = ∅ ↔ s = ∅ := ⟨λ h, eq_empty_of_forall_not_mem $ λ a m, ne_empty_of_mem (mem_image_of_mem _ m) h, λ e, e.symm ▸ rfl⟩ lemma attach_image_val [decidable_eq α] {s : finset α} : s.attach.image subtype.val = s := eq_of_veq $ by rw [image_val, attach_val, multiset.attach_map_val, erase_dup_eq_self] @[simp] lemma attach_insert [decidable_eq α] {a : α} {s : finset α} : attach (insert a s) = insert (⟨a, mem_insert_self a s⟩ : {x // x ∈ insert a s}) ((attach s).image (λx, ⟨x.1, mem_insert_of_mem x.2⟩)) := ext.2 $ λ ⟨x, hx⟩, ⟨or.cases_on (mem_insert.1 hx) (assume h : x = a, λ _, mem_insert.2 $ or.inl $ subtype.eq h) (assume h : x ∈ s, λ _, mem_insert_of_mem $ mem_image.2 $ ⟨⟨x, h⟩, mem_attach _ _, subtype.eq rfl⟩), λ _, finset.mem_attach _ _⟩ theorem map_eq_image (f : α ↪ β) (s : finset α) : s.map f = s.image f := eq_of_veq $ (multiset.erase_dup_eq_self.2 (s.map f).2).symm lemma image_const {s : finset α} (h : s.nonempty) (b : β) : s.image (λa, b) = singleton b := ext.2 $ assume b', by simp only [mem_image, exists_prop, exists_and_distrib_right, h.bex, true_and, mem_singleton, eq_comm] /-- Given a finset `s` and a predicate `p`, `s.subtype p` is the finset of `subtype p` whose elements belong to `s`. -/ protected def subtype {α} (p : α → Prop) [decidable_pred p] (s : finset α) : finset (subtype p) := (s.filter p).attach.map ⟨λ x, ⟨x.1, (finset.mem_filter.1 x.2).2⟩, λ x y H, subtype.eq $ subtype.mk.inj H⟩ @[simp] lemma mem_subtype {p : α → Prop} [decidable_pred p] {s : finset α} : ∀{a : subtype p}, a ∈ s.subtype p ↔ a.val ∈ s | ⟨a, ha⟩ := by simp [finset.subtype, ha] lemma subset_image_iff [decidable_eq α] {f : α → β} {s : finset β} {t : set α} : ↑s ⊆ f '' t ↔ ∃s' : finset α, ↑s' ⊆ t ∧ s'.image f = s := begin split, swap, { rintro ⟨s, hs, rfl⟩, rw [coe_image], exact set.image_subset f hs }, intro h, induction s using finset.induction with a s has ih h, { exact ⟨∅, set.empty_subset _, finset.image_empty _⟩ }, rw [finset.coe_insert, set.insert_subset] at h, rcases ih h.2 with ⟨s', hst, hsi⟩, rcases h.1 with ⟨x, hxt, rfl⟩, refine ⟨insert x s', _, _⟩, { rw [finset.coe_insert, set.insert_subset], exact ⟨hxt, hst⟩ }, rw [finset.image_insert, hsi] end end image /-! ### card -/ section card /-- `card s` is the cardinality (number of elements) of `s`. -/ def card (s : finset α) : nat := s.1.card theorem card_def (s : finset α) : s.card = s.1.card := rfl @[simp] theorem card_empty : card (∅ : finset α) = 0 := rfl @[simp] theorem card_eq_zero {s : finset α} : card s = 0 ↔ s = ∅ := card_eq_zero.trans val_eq_zero theorem card_pos {s : finset α} : 0 < card s ↔ s.nonempty := pos_iff_ne_zero.trans $ (not_congr card_eq_zero).trans nonempty_iff_ne_empty.symm theorem card_ne_zero_of_mem {s : finset α} {a : α} (h : a ∈ s) : card s ≠ 0 := (not_congr card_eq_zero).2 (ne_empty_of_mem h) theorem card_eq_one {s : finset α} : s.card = 1 ↔ ∃ a, s = finset.singleton a := by cases s; simp [multiset.card_eq_one, finset.singleton, finset.card] @[simp] theorem card_insert_of_not_mem [decidable_eq α] {a : α} {s : finset α} (h : a ∉ s) : card (insert a s) = card s + 1 := by simpa only [card_cons, card, insert_val] using congr_arg multiset.card (ndinsert_of_not_mem h) theorem card_insert_le [decidable_eq α] (a : α) (s : finset α) : card (insert a s) ≤ card s + 1 := by by_cases a ∈ s; [{rw [insert_eq_of_mem h], apply nat.le_add_right}, rw [card_insert_of_not_mem h]] @[simp] theorem card_singleton (a : α) : card (singleton a) = 1 := card_singleton _ theorem card_erase_of_mem [decidable_eq α] {a : α} {s : finset α} : a ∈ s → card (erase s a) = pred (card s) := card_erase_of_mem theorem card_erase_lt_of_mem [decidable_eq α] {a : α} {s : finset α} : a ∈ s → card (erase s a) < card s := card_erase_lt_of_mem theorem card_erase_le [decidable_eq α] {a : α} {s : finset α} : card (erase s a) ≤ card s := card_erase_le @[simp] theorem card_range (n : ℕ) : card (range n) = n := card_range n @[simp] theorem card_attach {s : finset α} : card (attach s) = card s := multiset.card_attach theorem card_image_of_inj_on [decidable_eq β] {f : α → β} {s : finset α} (H : ∀x∈s, ∀y∈s, f x = f y → x = y) : card (image f s) = card s := by simp only [card, image_val_of_inj_on H, card_map] theorem card_image_of_injective [decidable_eq β] {f : α → β} (s : finset α) (H : function.injective f) : card (image f s) = card s := card_image_of_inj_on $ λ x _ y _ h, H h @[simp] lemma card_map {α β} [decidable_eq β] (f : α ↪ β) {s : finset α} : (s.map f).card = s.card := by rw [map_eq_image, card_image_of_injective]; exact f.2 lemma card_eq_of_bijective [decidable_eq α] {s : finset α} {n : ℕ} (f : ∀i, i < n → α) (hf : ∀a∈s, ∃i, ∃h:i<n, f i h = a) (hf' : ∀i (h : i < n), f i h ∈ s) (f_inj : ∀i j (hi : i < n) (hj : j < n), f i hi = f j hj → i = j) : card s = n := have ∀ (a : α), a ∈ s ↔ ∃i (hi : i ∈ range n), f i (mem_range.1 hi) = a, from assume a, ⟨assume ha, let ⟨i, hi, eq⟩ := hf a ha in ⟨i, mem_range.2 hi, eq⟩, assume ⟨i, hi, eq⟩, eq ▸ hf' i (mem_range.1 hi)⟩, have s = ((range n).attach.image $ λi, f i.1 (mem_range.1 i.2)), by simpa only [ext, mem_image, exists_prop, subtype.exists, mem_attach, true_and], calc card s = card ((range n).attach.image $ λi, f i.1 (mem_range.1 i.2)) : by rw [this] ... = card ((range n).attach) : card_image_of_injective _ $ assume ⟨i, hi⟩ ⟨j, hj⟩ eq, subtype.eq $ f_inj i j (mem_range.1 hi) (mem_range.1 hj) eq ... = card (range n) : card_attach ... = n : card_range n lemma card_eq_succ [decidable_eq α] {s : finset α} {n : ℕ} : s.card = n + 1 ↔ (∃a t, a ∉ t ∧ insert a t = s ∧ card t = n) := iff.intro (assume eq, have 0 < card s, from eq.symm ▸ nat.zero_lt_succ _, let ⟨a, has⟩ := card_pos.mp this in ⟨a, s.erase a, s.not_mem_erase a, insert_erase has, by simp only [eq, card_erase_of_mem has, pred_succ]⟩) (assume ⟨a, t, hat, s_eq, n_eq⟩, s_eq ▸ n_eq ▸ card_insert_of_not_mem hat) theorem card_le_of_subset {s t : finset α} : s ⊆ t → card s ≤ card t := multiset.card_le_of_le ∘ val_le_iff.mpr theorem eq_of_subset_of_card_le {s t : finset α} (h : s ⊆ t) (h₂ : card t ≤ card s) : s = t := eq_of_veq $ multiset.eq_of_le_of_card_le (val_le_iff.mpr h) h₂ lemma card_lt_card {s t : finset α} (h : s ⊂ t) : s.card < t.card := card_lt_of_lt (val_lt_iff.2 h) lemma card_le_card_of_inj_on [decidable_eq β] {s : finset α} {t : finset β} (f : α → β) (hf : ∀a∈s, f a ∈ t) (f_inj : ∀a₁∈s, ∀a₂∈s, f a₁ = f a₂ → a₁ = a₂) : card s ≤ card t := calc card s = card (s.image f) : by rw [card_image_of_inj_on f_inj] ... ≤ card t : card_le_of_subset $ assume x hx, match x, finset.mem_image.1 hx with _, ⟨a, ha, rfl⟩ := hf a ha end lemma card_le_of_inj_on [decidable_eq α] {n} {s : finset α} (f : ℕ → α) (hf : ∀i<n, f i ∈ s) (f_inj : ∀i j, i<n → j<n → f i = f j → i = j) : n ≤ card s := calc n = card (range n) : (card_range n).symm ... ≤ card s : card_le_card_of_inj_on f (by simpa only [mem_range]) (by simp only [mem_range]; exact assume a₁ h₁ a₂ h₂, f_inj a₁ a₂ h₁ h₂) /-- Suppose that, given objects defined on all strict subsets of any finset `s`, one knows how to define an object on `s`. Then one can inductively define an object on all finsets, starting from the empty set and iterating. This can be used either to define data, or to prove properties. -/ @[elab_as_eliminator] def strong_induction_on {p : finset α → Sort*} : ∀ (s : finset α), (∀s, (∀t ⊂ s, p t) → p s) → p s | ⟨s, nd⟩ ih := multiset.strong_induction_on s (λ s IH nd, ih ⟨s, nd⟩ (λ ⟨t, nd'⟩ ss, IH t (val_lt_iff.2 ss) nd')) nd @[elab_as_eliminator] lemma case_strong_induction_on [decidable_eq α] {p : finset α → Prop} (s : finset α) (h₀ : p ∅) (h₁ : ∀ a s, a ∉ s → (∀t ⊆ s, p t) → p (insert a s)) : p s := finset.strong_induction_on s $ λ s, finset.induction_on s (λ _, h₀) $ λ a s n _ ih, h₁ a s n $ λ t ss, ih _ (lt_of_le_of_lt ss (ssubset_insert n) : t < _) lemma card_congr {s : finset α} {t : finset β} (f : Π a ∈ s, β) (h₁ : ∀ a ha, f a ha ∈ t) (h₂ : ∀ a b ha hb, f a ha = f b hb → a = b) (h₃ : ∀ b ∈ t, ∃ a ha, f a ha = b) : s.card = t.card := by haveI := classical.prop_decidable; exact calc s.card = s.attach.card : card_attach.symm ... = (s.attach.image (λ (a : {a // a ∈ s}), f a.1 a.2)).card : eq.symm (card_image_of_injective _ (λ a b h, subtype.eq (h₂ _ _ _ _ h))) ... = t.card : congr_arg card (finset.ext.2 $ λ b, ⟨λ h, let ⟨a, ha₁, ha₂⟩ := mem_image.1 h in ha₂ ▸ h₁ _ _, λ h, let ⟨a, ha₁, ha₂⟩ := h₃ b h in mem_image.2 ⟨⟨a, ha₁⟩, by simp [ha₂]⟩⟩) lemma card_union_add_card_inter [decidable_eq α] (s t : finset α) : (s ∪ t).card + (s ∩ t).card = s.card + t.card := finset.induction_on t (by simp) $ λ a r har, by by_cases a ∈ s; simp *; cc lemma card_union_le [decidable_eq α] (s t : finset α) : (s ∪ t).card ≤ s.card + t.card := card_union_add_card_inter s t ▸ le_add_right _ _ lemma surj_on_of_inj_on_of_card_le {s : finset α} {t : finset β} (f : Π a ∈ s, β) (hf : ∀ a ha, f a ha ∈ t) (hinj : ∀ a₁ a₂ ha₁ ha₂, f a₁ ha₁ = f a₂ ha₂ → a₁ = a₂) (hst : card t ≤ card s) : (∀ b ∈ t, ∃ a ha, b = f a ha) := by haveI := classical.dec_eq β; exact λ b hb, have h : card (image (λ (a : {a // a ∈ s}), f (a.val) a.2) (attach s)) = card s, from @card_attach _ s ▸ card_image_of_injective _ (λ ⟨a₁, ha₁⟩ ⟨a₂, ha₂⟩ h, subtype.eq $ hinj _ _ _ _ h), have h₁ : image (λ a : {a // a ∈ s}, f a.1 a.2) s.attach = t := eq_of_subset_of_card_le (λ b h, let ⟨a, ha₁, ha₂⟩ := mem_image.1 h in ha₂ ▸ hf _ _) (by simp [hst, h]), begin rw ← h₁ at hb, rcases mem_image.1 hb with ⟨a, ha₁, ha₂⟩, exact ⟨a, a.2, ha₂.symm⟩, end open function lemma inj_on_of_surj_on_of_card_le {s : finset α} {t : finset β} (f : Π a ∈ s, β) (hf : ∀ a ha, f a ha ∈ t) (hsurj : ∀ b ∈ t, ∃ a ha, b = f a ha) (hst : card s ≤ card t) ⦃a₁ a₂⦄ (ha₁ : a₁ ∈ s) (ha₂ : a₂ ∈ s) (ha₁a₂: f a₁ ha₁ = f a₂ ha₂) : a₁ = a₂ := by haveI : inhabited {x // x ∈ s} := ⟨⟨a₁, ha₁⟩⟩; exact let f' : {x // x ∈ s} → {x // x ∈ t} := λ x, ⟨f x.1 x.2, hf x.1 x.2⟩ in let g : {x // x ∈ t} → {x // x ∈ s} := @surj_inv _ _ f' (λ x, let ⟨y, hy₁, hy₂⟩ := hsurj x.1 x.2 in ⟨⟨y, hy₁⟩, subtype.eq hy₂.symm⟩) in have hg : injective g, from function.injective_surj_inv _, have hsg : surjective g, from λ x, let ⟨y, hy⟩ := surj_on_of_inj_on_of_card_le (λ (x : {x // x ∈ t}) (hx : x ∈ t.attach), g x) (λ x _, show (g x) ∈ s.attach, from mem_attach _ _) (λ x y _ _ hxy, hg hxy) (by simpa) x (mem_attach _ _) in ⟨y, hy.snd.symm⟩, have hif : injective f', from injective_of_has_left_inverse ⟨g, left_inverse_of_surjective_of_right_inverse hsg (right_inverse_surj_inv _)⟩, subtype.ext.1 (@hif ⟨a₁, ha₁⟩ ⟨a₂, ha₂⟩ (subtype.eq ha₁a₂)) end card /-! ### bind -/ section bind variables [decidable_eq β] {s : finset α} {t : α → finset β} /-- `bind s t` is the union of `t x` over `x ∈ s` -/ protected def bind (s : finset α) (t : α → finset β) : finset β := (s.1.bind (λ a, (t a).1)).to_finset @[simp] theorem bind_val (s : finset α) (t : α → finset β) : (s.bind t).1 = (s.1.bind (λ a, (t a).1)).erase_dup := rfl @[simp] theorem bind_empty : finset.bind ∅ t = ∅ := rfl @[simp] theorem mem_bind {b : β} : b ∈ s.bind t ↔ ∃a∈s, b ∈ t a := by simp only [mem_def, bind_val, mem_erase_dup, mem_bind, exists_prop] @[simp] theorem bind_insert [decidable_eq α] {a : α} : (insert a s).bind t = t a ∪ s.bind t := ext.2 $ λ x, by simp only [mem_bind, exists_prop, mem_union, mem_insert, or_and_distrib_right, exists_or_distrib, exists_eq_left] -- ext.2 $ λ x, by simp [or_and_distrib_right, exists_or_distrib] @[simp] lemma singleton_bind [decidable_eq α] {a : α} : (singleton a).bind t = t a := show (insert a ∅ : finset α).bind t = t a, from bind_insert.trans $ union_empty _ theorem bind_inter (s : finset α) (f : α → finset β) (t : finset β) : s.bind f ∩ t = s.bind (λ x, f x ∩ t) := begin ext x, simp only [mem_bind, mem_inter], tauto end theorem inter_bind (t : finset β) (s : finset α) (f : α → finset β) : t ∩ s.bind f = s.bind (λ x, t ∩ f x) := by rw [inter_comm, bind_inter]; simp [inter_comm] theorem image_bind [decidable_eq γ] {f : α → β} {s : finset α} {t : β → finset γ} : (s.image f).bind t = s.bind (λa, t (f a)) := by haveI := classical.dec_eq α; exact finset.induction_on s rfl (λ a s has ih, by simp only [image_insert, bind_insert, ih]) theorem bind_image [decidable_eq γ] {s : finset α} {t : α → finset β} {f : β → γ} : (s.bind t).image f = s.bind (λa, (t a).image f) := by haveI := classical.dec_eq α; exact finset.induction_on s rfl (λ a s has ih, by simp only [bind_insert, image_union, ih]) theorem bind_to_finset [decidable_eq α] (s : multiset α) (t : α → multiset β) : (s.bind t).to_finset = s.to_finset.bind (λa, (t a).to_finset) := ext.2 $ λ x, by simp only [multiset.mem_to_finset, mem_bind, multiset.mem_bind, exists_prop] lemma bind_mono {t₁ t₂ : α → finset β} (h : ∀a∈s, t₁ a ⊆ t₂ a) : s.bind t₁ ⊆ s.bind t₂ := have ∀b a, a ∈ s → b ∈ t₁ a → (∃ (a : α), a ∈ s ∧ b ∈ t₂ a), from assume b a ha hb, ⟨a, ha, finset.mem_of_subset (h a ha) hb⟩, by simpa only [subset_iff, mem_bind, exists_imp_distrib, and_imp, exists_prop] lemma bind_singleton {f : α → β} : s.bind (λa, {f a}) = s.image f := ext.2 $ λ x, by simp only [mem_bind, mem_image, insert_empty_eq_singleton, mem_singleton, eq_comm] lemma image_bind_filter_eq [decidable_eq α] (s : finset β) (g : β → α) : (s.image g).bind (λa, s.filter $ (λc, g c = a)) = s := begin ext b, simp, split, { rintros ⟨a, ⟨b', _, _⟩, hb, _⟩, exact hb }, { rintros hb, exact ⟨g b, ⟨b, hb, rfl⟩, hb, rfl⟩ } end end bind /-! ### prod-/ section prod variables {s : finset α} {t : finset β} /-- `product s t` is the set of pairs `(a, b)` such that `a ∈ s` and `b ∈ t`. -/ protected def product (s : finset α) (t : finset β) : finset (α × β) := ⟨_, nodup_product s.2 t.2⟩ @[simp] theorem product_val : (s.product t).1 = s.1.product t.1 := rfl @[simp] theorem mem_product {p : α × β} : p ∈ s.product t ↔ p.1 ∈ s ∧ p.2 ∈ t := mem_product theorem product_eq_bind [decidable_eq α] [decidable_eq β] (s : finset α) (t : finset β) : s.product t = s.bind (λa, t.image $ λb, (a, b)) := ext.2 $ λ ⟨x, y⟩, by simp only [mem_product, mem_bind, mem_image, exists_prop, prod.mk.inj_iff, and.left_comm, exists_and_distrib_left, exists_eq_right, exists_eq_left] @[simp] theorem card_product (s : finset α) (t : finset β) : card (s.product t) = card s * card t := multiset.card_product _ _ end prod /-! ### sigma -/ section sigma variables {σ : α → Type*} {s : finset α} {t : Πa, finset (σ a)} /-- `sigma s t` is the set of dependent pairs `⟨a, b⟩` such that `a ∈ s` and `b ∈ t a`. -/ protected def sigma (s : finset α) (t : Πa, finset (σ a)) : finset (Σa, σ a) := ⟨_, nodup_sigma s.2 (λ a, (t a).2)⟩ @[simp] theorem mem_sigma {p : sigma σ} : p ∈ s.sigma t ↔ p.1 ∈ s ∧ p.2 ∈ t (p.1) := mem_sigma theorem sigma_mono {s₁ s₂ : finset α} {t₁ t₂ : Πa, finset (σ a)} (H1 : s₁ ⊆ s₂) (H2 : ∀a, t₁ a ⊆ t₂ a) : s₁.sigma t₁ ⊆ s₂.sigma t₂ := λ ⟨x, sx⟩ H, let ⟨H3, H4⟩ := mem_sigma.1 H in mem_sigma.2 ⟨H1 H3, H2 x H4⟩ theorem sigma_eq_bind [decidable_eq α] [∀a, decidable_eq (σ a)] (s : finset α) (t : Πa, finset (σ a)) : s.sigma t = s.bind (λa, (t a).image $ λb, ⟨a, b⟩) := ext.2 $ λ ⟨x, y⟩, by simp only [mem_sigma, mem_bind, mem_image, exists_prop, and.left_comm, exists_and_distrib_left, exists_eq_left, heq_iff_eq, exists_eq_right] end sigma /-! ### pi -/ section pi variables {δ : α → Type*} [decidable_eq α] /-- Given a finset `s` of `α` and for all `a : α` a finset `t a` of `δ a`, then one can define the finset `s.pi t` of all functions defined on elements of `s` taking values in `t a` for `a ∈ s`. Note that the elements of `s.pi t` are only partially defined, on `s`. -/ def pi (s : finset α) (t : Πa, finset (δ a)) : finset (Πa∈s, δ a) := ⟨s.1.pi (λ a, (t a).1), nodup_pi s.2 (λ a _, (t a).2)⟩ @[simp] lemma pi_val (s : finset α) (t : Πa, finset (δ a)) : (s.pi t).1 = s.1.pi (λ a, (t a).1) := rfl @[simp] lemma mem_pi {s : finset α} {t : Πa, finset (δ a)} {f : Πa∈s, δ a} : f ∈ s.pi t ↔ (∀a (h : a ∈ s), f a h ∈ t a) := mem_pi _ _ _ /-- The empty dependent product function, defined on the emptyset. The assumption `a ∈ ∅` is never satisfied. -/ def pi.empty (β : α → Sort*) (a : α) (h : a ∈ (∅ : finset α)) : β a := multiset.pi.empty β a h /-- Given a function `f` defined on a finset `s`, define a new function on the finset `s ∪ {a}`, equal to `f` on `s` and sending `a` to a given value `b`. This function is denoted `s.pi.cons a b f`. If `a` already belongs to `s`, the new function takes the value `b` at `a` anyway. -/ def pi.cons (s : finset α) (a : α) (b : δ a) (f : Πa, a ∈ s → δ a) (a' : α) (h : a' ∈ insert a s) : δ a' := multiset.pi.cons s.1 a b f _ (multiset.mem_cons.2 $ mem_insert.symm.2 h) @[simp] lemma pi.cons_same (s : finset α) (a : α) (b : δ a) (f : Πa, a ∈ s → δ a) (h : a ∈ insert a s) : pi.cons s a b f a h = b := multiset.pi.cons_same _ lemma pi.cons_ne {s : finset α} {a a' : α} {b : δ a} {f : Πa, a ∈ s → δ a} {h : a' ∈ insert a s} (ha : a ≠ a') : pi.cons s a b f a' h = f a' ((mem_insert.1 h).resolve_left ha.symm) := multiset.pi.cons_ne _ _ lemma injective_pi_cons {a : α} {b : δ a} {s : finset α} (hs : a ∉ s) : function.injective (pi.cons s a b) := assume e₁ e₂ eq, @multiset.injective_pi_cons α _ δ a b s.1 hs _ _ $ funext $ assume e, funext $ assume h, have pi.cons s a b e₁ e (by simpa only [mem_cons, mem_insert] using h) = pi.cons s a b e₂ e (by simpa only [mem_cons, mem_insert] using h), by rw [eq], this @[simp] lemma pi_empty {t : Πa:α, finset (δ a)} : pi (∅ : finset α) t = singleton (pi.empty δ) := rfl @[simp] lemma pi_insert [∀a, decidable_eq (δ a)] {s : finset α} {t : Πa:α, finset (δ a)} {a : α} (ha : a ∉ s) : pi (insert a s) t = (t a).bind (λb, (pi s t).image (pi.cons s a b)) := begin apply eq_of_veq, rw ← multiset.erase_dup_eq_self.2 (pi (insert a s) t).2, refine (λ s' (h : s' = a :: s.1), (_ : erase_dup (multiset.pi s' (λ a, (t a).1)) = erase_dup ((t a).1.bind $ λ b, erase_dup $ (multiset.pi s.1 (λ (a : α), (t a).val)).map $ λ f a' h', multiset.pi.cons s.1 a b f a' (h ▸ h')))) _ (insert_val_of_not_mem ha), subst s', rw pi_cons, congr, funext b, rw multiset.erase_dup_eq_self.2, exact multiset.nodup_map (multiset.injective_pi_cons ha) (pi s t).2, end lemma pi_subset {s : finset α} (t₁ t₂ : Πa, finset (δ a)) (h : ∀ a ∈ s, t₁ a ⊆ t₂ a) : s.pi t₁ ⊆ s.pi t₂ := λ g hg, mem_pi.2 $ λ a ha, h a ha (mem_pi.mp hg a ha) end pi /-! ### powerset -/ section powerset /-- When `s` is a finset, `s.powerset` is the finset of all subsets of `s` (seen as finsets). -/ def powerset (s : finset α) : finset (finset α) := ⟨s.1.powerset.pmap finset.mk (λ t h, nodup_of_le (mem_powerset.1 h) s.2), nodup_pmap (λ a ha b hb, congr_arg finset.val) (nodup_powerset.2 s.2)⟩ @[simp] theorem mem_powerset {s t : finset α} : s ∈ powerset t ↔ s ⊆ t := by cases s; simp only [powerset, mem_mk, mem_pmap, mem_powerset, exists_prop, exists_eq_right]; rw ← val_le_iff @[simp] theorem empty_mem_powerset (s : finset α) : ∅ ∈ powerset s := mem_powerset.2 (empty_subset _) @[simp] theorem mem_powerset_self (s : finset α) : s ∈ powerset s := mem_powerset.2 (subset.refl _) @[simp] lemma powerset_empty [decidable_eq α] : finset.powerset (∅ : finset α) = {∅} := rfl @[simp] theorem powerset_mono {s t : finset α} : powerset s ⊆ powerset t ↔ s ⊆ t := ⟨λ h, (mem_powerset.1 $ h $ mem_powerset_self _), λ st u h, mem_powerset.2 $ subset.trans (mem_powerset.1 h) st⟩ @[simp] theorem card_powerset (s : finset α) : card (powerset s) = 2 ^ card s := (card_pmap _ _ _).trans (card_powerset s.1) lemma not_mem_of_mem_powerset_of_not_mem {s t : finset α} {a : α} (ht : t ∈ s.powerset) (h : a ∉ s) : a ∉ t := by { apply mt _ h, apply mem_powerset.1 ht } lemma powerset_insert [decidable_eq α] (s : finset α) (a : α) : powerset (insert a s) = s.powerset ∪ s.powerset.image (insert a) := begin ext t, simp only [exists_prop, mem_powerset, mem_image, mem_union, subset_insert_iff], by_cases h : a ∈ t, { split, { exact λH, or.inr ⟨_, H, insert_erase h⟩ }, { intros H, cases H, { exact subset.trans (erase_subset a t) H }, { rcases H with ⟨u, hu⟩, rw ← hu.2, exact subset.trans (erase_insert_subset a u) hu.1 } } }, { have : ¬ ∃ (u : finset α), u ⊆ s ∧ insert a u = t, by simp [ne.symm (ne_insert_of_not_mem _ _ h)], simp [finset.erase_eq_of_not_mem h, this] } end end powerset section powerset_len /-- Given an integer `n` and a finset `s`, then `powerset_len n s` is the finset of subsets of `s` of cardinality `n`.-/ def powerset_len (n : ℕ) (s : finset α) : finset (finset α) := ⟨(s.1.powerset_len n).pmap finset.mk (λ t h, nodup_of_le (mem_powerset_len.1 h).1 s.2), nodup_pmap (λ a ha b hb, congr_arg finset.val) (nodup_powerset_len s.2)⟩ theorem mem_powerset_len {n} {s t : finset α} : s ∈ powerset_len n t ↔ s ⊆ t ∧ card s = n := by cases s; simp [powerset_len, val_le_iff.symm]; refl @[simp] theorem powerset_len_mono {n} {s t : finset α} (h : s ⊆ t) : powerset_len n s ⊆ powerset_len n t := λ u h', mem_powerset_len.2 $ and.imp (λ h₂, subset.trans h₂ h) id (mem_powerset_len.1 h') @[simp] theorem card_powerset_len (n : ℕ) (s : finset α) : card (powerset_len n s) = nat.choose (card s) n := (card_pmap _ _ _).trans (card_powerset_len n s.1) end powerset_len /-! ### fold -/ section fold variables (op : β → β → β) [hc : is_commutative β op] [ha : is_associative β op] local notation a * b := op a b include hc ha /-- `fold op b f s` folds the commutative associative operation `op` over the `f`-image of `s`, i.e. `fold (+) b f {1,2,3} = `f 1 + f 2 + f 3 + b`. -/ def fold (b : β) (f : α → β) (s : finset α) : β := (s.1.map f).fold op b variables {op} {f : α → β} {b : β} {s : finset α} {a : α} @[simp] theorem fold_empty : (∅ : finset α).fold op b f = b := rfl @[simp] theorem fold_insert [decidable_eq α] (h : a ∉ s) : (insert a s).fold op b f = f a * s.fold op b f := by unfold fold; rw [insert_val, ndinsert_of_not_mem h, map_cons, fold_cons_left] @[simp] theorem fold_singleton : (singleton a).fold op b f = f a * b := rfl @[simp] theorem fold_map {g : γ ↪ α} {s : finset γ} : (s.map g).fold op b f = s.fold op b (f ∘ g) := by simp only [fold, map, multiset.map_map] @[simp] theorem fold_image [decidable_eq α] {g : γ → α} {s : finset γ} (H : ∀ (x ∈ s) (y ∈ s), g x = g y → x = y) : (s.image g).fold op b f = s.fold op b (f ∘ g) := by simp only [fold, image_val_of_inj_on H, multiset.map_map] @[congr] theorem fold_congr {g : α → β} (H : ∀ x ∈ s, f x = g x) : s.fold op b f = s.fold op b g := by rw [fold, fold, map_congr H] theorem fold_op_distrib {f g : α → β} {b₁ b₂ : β} : s.fold op (b₁ * b₂) (λx, f x * g x) = s.fold op b₁ f * s.fold op b₂ g := by simp only [fold, fold_distrib] theorem fold_hom {op' : γ → γ → γ} [is_commutative γ op'] [is_associative γ op'] {m : β → γ} (hm : ∀x y, m (op x y) = op' (m x) (m y)) : s.fold op' (m b) (λx, m (f x)) = m (s.fold op b f) := by rw [fold, fold, ← fold_hom op hm, multiset.map_map] theorem fold_union_inter [decidable_eq α] {s₁ s₂ : finset α} {b₁ b₂ : β} : (s₁ ∪ s₂).fold op b₁ f * (s₁ ∩ s₂).fold op b₂ f = s₁.fold op b₂ f * s₂.fold op b₁ f := by unfold fold; rw [← fold_add op, ← map_add, union_val, inter_val, union_add_inter, map_add, hc.comm, fold_add] @[simp] theorem fold_insert_idem [decidable_eq α] [hi : is_idempotent β op] : (insert a s).fold op b f = f a * s.fold op b f := by haveI := classical.prop_decidable; rw [fold, insert_val', ← fold_erase_dup_idem op, erase_dup_map_erase_dup_eq, fold_erase_dup_idem op]; simp only [map_cons, fold_cons_left, fold] lemma fold_op_rel_iff_and [decidable_eq α] {r : β → β → Prop} (hr : ∀ {x y z}, r x (op y z) ↔ (r x y ∧ r x z)) {c : β} : r c (s.fold op b f) ↔ (r c b ∧ ∀ x∈s, r c (f x)) := begin apply finset.induction_on s, { simp }, clear s, intros a s ha IH, rw [finset.fold_insert ha, hr, IH, ← and_assoc, and_comm (r c (f a)), and_assoc], apply and_congr iff.rfl, split, { rintro ⟨h₁, h₂⟩, intros b hb, rw finset.mem_insert at hb, rcases hb with rfl|hb; solve_by_elim }, { intro h, split, { exact h a (finset.mem_insert_self _ _), }, { intros b hb, apply h b, rw finset.mem_insert, right, exact hb } } end lemma fold_op_rel_iff_or [decidable_eq α] {r : β → β → Prop} (hr : ∀ {x y z}, r x (op y z) ↔ (r x y ∨ r x z)) {c : β} : r c (s.fold op b f) ↔ (r c b ∨ ∃ x∈s, r c (f x)) := begin apply finset.induction_on s, { simp }, clear s, intros a s ha IH, rw [finset.fold_insert ha, hr, IH, ← or_assoc, or_comm (r c (f a)), or_assoc], apply or_congr iff.rfl, split, { rintro (h₁|⟨x, hx, h₂⟩), { use a, simp [h₁] }, { refine ⟨x, by simp [hx], h₂⟩ } }, { rintro ⟨x, hx, h⟩, rw mem_insert at hx, cases hx, { left, rwa hx at h }, { right, exact ⟨x, hx, h⟩ } } end omit hc ha section order variables [decidable_eq α] [decidable_linear_order β] (c : β) lemma le_fold_min : c ≤ s.fold min b f ↔ (c ≤ b ∧ ∀ x∈s, c ≤ f x) := fold_op_rel_iff_and $ λ x y z, le_min_iff lemma fold_min_le : s.fold min b f ≤ c ↔ (b ≤ c ∨ ∃ x∈s, f x ≤ c) := begin show _ ≥ _ ↔ _, apply fold_op_rel_iff_or, intros x y z, show _ ≤ _ ↔ _, exact min_le_iff end lemma lt_fold_min : c < s.fold min b f ↔ (c < b ∧ ∀ x∈s, c < f x) := fold_op_rel_iff_and $ λ x y z, lt_min_iff lemma fold_min_lt : s.fold min b f < c ↔ (b < c ∨ ∃ x∈s, f x < c) := begin show _ > _ ↔ _, apply fold_op_rel_iff_or, intros x y z, show _ < _ ↔ _, exact min_lt_iff end lemma fold_max_le : s.fold max b f ≤ c ↔ (b ≤ c ∧ ∀ x∈s, f x ≤ c) := begin show _ ≥ _ ↔ _, apply fold_op_rel_iff_and, intros x y z, show _ ≤ _ ↔ _, exact max_le_iff end lemma le_fold_max : c ≤ s.fold max b f ↔ (c ≤ b ∨ ∃ x∈s, c ≤ f x) := fold_op_rel_iff_or $ λ x y z, le_max_iff lemma fold_max_lt : s.fold max b f < c ↔ (b < c ∧ ∀ x∈s, f x < c) := begin show _ > _ ↔ _, apply fold_op_rel_iff_and, intros x y z, show _ < _ ↔ _, exact max_lt_iff end lemma lt_fold_max : c < s.fold max b f ↔ (c < b ∨ ∃ x∈s, c < f x) := fold_op_rel_iff_or $ λ x y z, lt_max_iff end order end fold /-! ### sup -/ section sup variables [semilattice_sup_bot α] /-- Supremum of a finite set: `sup {a, b, c} f = f a ⊔ f b ⊔ f c` -/ def sup (s : finset β) (f : β → α) : α := s.fold (⊔) ⊥ f variables {s s₁ s₂ : finset β} {f : β → α} lemma sup_val : s.sup f = (s.1.map f).sup := rfl @[simp] lemma sup_empty : (∅ : finset β).sup f = ⊥ := fold_empty @[simp] lemma sup_insert [decidable_eq β] {b : β} : (insert b s : finset β).sup f = f b ⊔ s.sup f := fold_insert_idem @[simp] lemma sup_singleton' {b : β} : (singleton b).sup f = f b := sup_singleton lemma sup_singleton [decidable_eq β] {b : β} : ({b} : finset β).sup f = f b := sup_singleton lemma sup_union [decidable_eq β] : (s₁ ∪ s₂).sup f = s₁.sup f ⊔ s₂.sup f := finset.induction_on s₁ (by rw [empty_union, sup_empty, bot_sup_eq]) $ λ a s has ih, by rw [insert_union, sup_insert, sup_insert, ih, sup_assoc] theorem sup_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀a∈s₂, f a = g a) : s₁.sup f = s₂.sup g := by subst hs; exact finset.fold_congr hfg lemma sup_mono_fun {g : β → α} : (∀b∈s, f b ≤ g b) → s.sup f ≤ s.sup g := by letI := classical.dec_eq β; from finset.induction_on s (λ _, le_refl _) (λ a s has ih H, by simp only [mem_insert, or_imp_distrib, forall_and_distrib, forall_eq] at H; simp only [sup_insert]; exact sup_le_sup H.1 (ih H.2)) lemma le_sup {b : β} (hb : b ∈ s) : f b ≤ s.sup f := by letI := classical.dec_eq β; from calc f b ≤ f b ⊔ s.sup f : le_sup_left ... = (insert b s).sup f : sup_insert.symm ... = s.sup f : by rw [insert_eq_of_mem hb] lemma sup_le {a : α} : (∀b ∈ s, f b ≤ a) → s.sup f ≤ a := by letI := classical.dec_eq β; from finset.induction_on s (λ _, bot_le) (λ n s hns ih H, by simp only [mem_insert, or_imp_distrib, forall_and_distrib, forall_eq] at H; simp only [sup_insert]; exact sup_le H.1 (ih H.2)) @[simp] lemma sup_le_iff {a : α} : s.sup f ≤ a ↔ (∀b ∈ s, f b ≤ a) := iff.intro (assume h b hb, le_trans (le_sup hb) h) sup_le lemma sup_mono (h : s₁ ⊆ s₂) : s₁.sup f ≤ s₂.sup f := sup_le $ assume b hb, le_sup (h hb) @[simp] lemma sup_lt_iff [is_total α (≤)] {a : α} (ha : ⊥ < a) : s.sup f < a ↔ (∀b ∈ s, f b < a) := by letI := classical.dec_eq β; from ⟨ λh b hb, lt_of_le_of_lt (le_sup hb) h, finset.induction_on s (by simp [ha]) (by simp {contextual := tt}) ⟩ lemma comp_sup_eq_sup_comp [is_total α (≤)] {γ : Type} [semilattice_sup_bot γ] (g : α → γ) (mono_g : monotone g) (bot : g ⊥ = ⊥) : g (s.sup f) = s.sup (g ∘ f) := have A : ∀x y, g (x ⊔ y) = g x ⊔ g y := begin assume x y, cases (is_total.total (≤) x y) with h, { simp [sup_of_le_right h, sup_of_le_right (mono_g h)] }, { simp [sup_of_le_left h, sup_of_le_left (mono_g h)] } end, by letI := classical.dec_eq β; from finset.induction_on s (by simp [bot]) (by simp [A] {contextual := tt}) theorem subset_range_sup_succ (s : finset ℕ) : s ⊆ range (s.sup id).succ := λ n hn, mem_range.2 $ nat.lt_succ_of_le $ le_sup hn theorem exists_nat_subset_range (s : finset ℕ) : ∃n : ℕ, s ⊆ range n := ⟨_, s.subset_range_sup_succ⟩ end sup lemma sup_eq_supr [complete_lattice β] (s : finset α) (f : α → β) : s.sup f = (⨆a∈s, f a) := le_antisymm (finset.sup_le $ assume a ha, le_supr_of_le a $ le_supr _ ha) (supr_le $ assume a, supr_le $ assume ha, le_sup ha) /-! ### inf -/ section inf variables [semilattice_inf_top α] /-- Infimum of a finite set: `inf {a, b, c} f = f a ⊓ f b ⊓ f c` -/ def inf (s : finset β) (f : β → α) : α := s.fold (⊓) ⊤ f variables {s s₁ s₂ : finset β} {f : β → α} lemma inf_val : s.inf f = (s.1.map f).inf := rfl @[simp] lemma inf_empty : (∅ : finset β).inf f = ⊤ := fold_empty @[simp] lemma inf_insert [decidable_eq β] {b : β} : (insert b s : finset β).inf f = f b ⊓ s.inf f := fold_insert_idem @[simp] lemma inf_singleton' {b : β} : (singleton b).inf f = f b := inf_singleton lemma inf_singleton [decidable_eq β] {b : β} : ({b} : finset β).inf f = f b := inf_singleton' lemma inf_union [decidable_eq β] : (s₁ ∪ s₂).inf f = s₁.inf f ⊓ s₂.inf f := finset.induction_on s₁ (by rw [empty_union, inf_empty, top_inf_eq]) $ λ a s has ih, by rw [insert_union, inf_insert, inf_insert, ih, inf_assoc] theorem inf_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀a∈s₂, f a = g a) : s₁.inf f = s₂.inf g := by subst hs; exact finset.fold_congr hfg lemma inf_mono_fun {g : β → α} : (∀b∈s, f b ≤ g b) → s.inf f ≤ s.inf g := by letI := classical.dec_eq β; from finset.induction_on s (λ _, le_refl _) (λ a s has ih H, by simp only [mem_insert, or_imp_distrib, forall_and_distrib, forall_eq] at H; simp only [inf_insert]; exact inf_le_inf H.1 (ih H.2)) lemma inf_le {b : β} (hb : b ∈ s) : s.inf f ≤ f b := by letI := classical.dec_eq β; from calc f b ≥ f b ⊓ s.inf f : inf_le_left ... = (insert b s).inf f : inf_insert.symm ... = s.inf f : by rw [insert_eq_of_mem hb] lemma le_inf {a : α} : (∀b ∈ s, a ≤ f b) → a ≤ s.inf f := by letI := classical.dec_eq β; from finset.induction_on s (λ _, le_top) (λ n s hns ih H, by simp only [mem_insert, or_imp_distrib, forall_and_distrib, forall_eq] at H; simp only [inf_insert]; exact le_inf H.1 (ih H.2)) lemma le_inf_iff {a : α} : a ≤ s.inf f ↔ (∀b ∈ s, a ≤ f b) := iff.intro (assume h b hb, le_trans h (inf_le hb)) le_inf lemma inf_mono (h : s₁ ⊆ s₂) : s₂.inf f ≤ s₁.inf f := le_inf $ assume b hb, inf_le (h hb) lemma lt_inf [is_total α (≤)] {a : α} : (a < ⊤) → (∀b ∈ s, a < f b) → a < s.inf f := by letI := classical.dec_eq β; from finset.induction_on s (by simp) (by simp {contextual := tt}) lemma comp_inf_eq_inf_comp [is_total α (≤)] {γ : Type} [semilattice_inf_top γ] (g : α → γ) (mono_g : monotone g) (top : g ⊤ = ⊤) : g (s.inf f) = s.inf (g ∘ f) := have A : ∀x y, g (x ⊓ y) = g x ⊓ g y := begin assume x y, cases (is_total.total (≤) x y) with h, { simp [inf_of_le_left h, inf_of_le_left (mono_g h)] }, { simp [inf_of_le_right h, inf_of_le_right (mono_g h)] } end, by letI := classical.dec_eq β; from finset.induction_on s (by simp [top]) (by simp [A] {contextual := tt}) end inf lemma inf_eq_infi [complete_lattice β] (s : finset α) (f : α → β) : s.inf f = (⨅a∈s, f a) := le_antisymm (le_infi $ assume a, le_infi $ assume ha, inf_le ha) (finset.le_inf $ assume a ha, infi_le_of_le a $ infi_le _ ha) /-! ### max and min of finite sets -/ section max_min variables [decidable_linear_order α] /-- Let `s` be a finset in a linear order. Then `s.max` is the maximum of `s` if `s` is not empty, and `none` otherwise. It belongs to `option α`. If you want to get an element of `α`, see `s.max'`. -/ protected def max : finset α → option α := fold (option.lift_or_get max) none some theorem max_eq_sup_with_bot (s : finset α) : s.max = @sup (with_bot α) α _ s some := rfl @[simp] theorem max_empty : (∅ : finset α).max = none := rfl @[simp] theorem max_insert {a : α} {s : finset α} : (insert a s).max = option.lift_or_get max (some a) s.max := fold_insert_idem theorem max_singleton {a : α} : finset.max {a} = some a := max_insert @[simp] theorem max_singleton' {a : α} : finset.max (singleton a) = some a := max_singleton theorem max_of_mem {s : finset α} {a : α} (h : a ∈ s) : ∃ b, b ∈ s.max := (@le_sup (with_bot α) _ _ _ _ _ h _ rfl).imp $ λ b, Exists.fst theorem max_of_nonempty {s : finset α} (h : s.nonempty) : ∃ a, a ∈ s.max := let ⟨a, ha⟩ := h in max_of_mem ha theorem max_eq_none {s : finset α} : s.max = none ↔ s = ∅ := ⟨λ h, s.eq_empty_or_nonempty.elim id (λ H, let ⟨a, ha⟩ := max_of_nonempty H in by rw h at ha; cases ha), λ h, h.symm ▸ max_empty⟩ theorem mem_of_max {s : finset α} : ∀ {a : α}, a ∈ s.max → a ∈ s := finset.induction_on s (λ _ H, by cases H) (λ b s _ (ih : ∀ {a}, a ∈ s.max → a ∈ s) a (h : a ∈ (insert b s).max), begin by_cases p : b = a, { induction p, exact mem_insert_self b s }, { cases option.lift_or_get_choice max_choice (some b) s.max with q q; rw [max_insert, q] at h, { cases h, cases p rfl }, { exact mem_insert_of_mem (ih h) } } end) theorem le_max_of_mem {s : finset α} {a b : α} (h₁ : a ∈ s) (h₂ : b ∈ s.max) : a ≤ b := by rcases @le_sup (with_bot α) _ _ _ _ _ h₁ _ rfl with ⟨b', hb, ab⟩; cases h₂.symm.trans hb; assumption /-- Let `s` be a finset in a linear order. Then `s.min` is the minimum of `s` if `s` is not empty, and `none` otherwise. It belongs to `option α`. If you want to get an element of `α`, see `s.min'`. -/ protected def min : finset α → option α := fold (option.lift_or_get min) none some theorem min_eq_inf_with_top (s : finset α) : s.min = @inf (with_top α) α _ s some := rfl @[simp] theorem min_empty : (∅ : finset α).min = none := rfl @[simp] theorem min_insert {a : α} {s : finset α} : (insert a s).min = option.lift_or_get min (some a) s.min := fold_insert_idem theorem min_singleton {a : α} : finset.min {a} = some a := min_insert @[simp] theorem min_singleton' {a : α} : finset.min (singleton a) = some a := min_singleton theorem min_of_mem {s : finset α} {a : α} (h : a ∈ s) : ∃ b, b ∈ s.min := (@inf_le (with_top α) _ _ _ _ _ h _ rfl).imp $ λ b, Exists.fst theorem min_of_nonempty {s : finset α} (h : s.nonempty) : ∃ a, a ∈ s.min := let ⟨a, ha⟩ := h in min_of_mem ha theorem min_eq_none {s : finset α} : s.min = none ↔ s = ∅ := ⟨λ h, s.eq_empty_or_nonempty.elim id (λ H, let ⟨a, ha⟩ := min_of_nonempty H in by rw h at ha; cases ha), λ h, h.symm ▸ min_empty⟩ theorem mem_of_min {s : finset α} : ∀ {a : α}, a ∈ s.min → a ∈ s := finset.induction_on s (λ _ H, by cases H) $ λ b s _ (ih : ∀ {a}, a ∈ s.min → a ∈ s) a (h : a ∈ (insert b s).min), begin by_cases p : b = a, { induction p, exact mem_insert_self b s }, { cases option.lift_or_get_choice min_choice (some b) s.min with q q; rw [min_insert, q] at h, { cases h, cases p rfl }, { exact mem_insert_of_mem (ih h) } } end theorem min_le_of_mem {s : finset α} {a b : α} (h₁ : b ∈ s) (h₂ : a ∈ s.min) : a ≤ b := by rcases @inf_le (with_top α) _ _ _ _ _ h₁ _ rfl with ⟨b', hb, ab⟩; cases h₂.symm.trans hb; assumption lemma exists_min (s : finset β) (f : β → α) (h : s.nonempty) : ∃ x ∈ s, ∀ x' ∈ s, f x ≤ f x' := begin cases min_of_nonempty (h.image f) with y hy, rcases mem_image.mp (mem_of_min hy) with ⟨x, hx, rfl⟩, exact ⟨x, hx, λ x' hx', min_le_of_mem (mem_image_of_mem f hx') hy⟩ end /-- Given a nonempty finset `s` in a linear order `α `, then `s.min' h` is its minimum, as an element of `α`, where `h` is a proof of nonemptiness. Without this assumption, use instead `s.min`, taking values in `option α`. -/ def min' (s : finset α) (H : s.nonempty) : α := @option.get _ s.min $ let ⟨k, hk⟩ := H in let ⟨b, hb⟩ := min_of_mem hk in by simp at hb; simp [hb] /-- Given a nonempty finset `s` in a linear order `α `, then `s.max' h` is its maximum, as an element of `α`, where `h` is a proof of nonemptiness. Without this assumption, use instead `s.max`, taking values in `option α`. -/ def max' (s : finset α) (H : s.nonempty) : α := @option.get _ s.max $ let ⟨k, hk⟩ := H in let ⟨b, hb⟩ := max_of_mem hk in by simp at hb; simp [hb] variables (s : finset α) (H : s.nonempty) theorem min'_mem : s.min' H ∈ s := mem_of_min $ by simp [min'] theorem min'_le (x) (H2 : x ∈ s) : s.min' H ≤ x := min_le_of_mem H2 $ option.get_mem _ theorem le_min' (x) (H2 : ∀ y ∈ s, x ≤ y) : x ≤ s.min' H := H2 _ $ min'_mem _ _ theorem max'_mem : s.max' H ∈ s := mem_of_max $ by simp [max'] theorem le_max' (x) (H2 : x ∈ s) : x ≤ s.max' H := le_max_of_mem H2 $ option.get_mem _ theorem max'_le (x) (H2 : ∀ y ∈ s, y ≤ x) : s.max' H ≤ x := H2 _ $ max'_mem _ _ theorem min'_lt_max' {i j} (H1 : i ∈ s) (H2 : j ∈ s) (H3 : i ≠ j) : s.min' H < s.max' H := begin rcases lt_trichotomy i j with H4 | H4 | H4, { have H5 := min'_le s H i H1, have H6 := le_max' s H j H2, apply lt_of_le_of_lt H5, apply lt_of_lt_of_le H4 H6 }, { cc }, { have H5 := min'_le s H j H2, have H6 := le_max' s H i H1, apply lt_of_le_of_lt H5, apply lt_of_lt_of_le H4 H6 } end end max_min /-! ### sort -/ section sort variables (r : α → α → Prop) [decidable_rel r] [is_trans α r] [is_antisymm α r] [is_total α r] /-- `sort s` constructs a sorted list from the unordered set `s`. (Uses merge sort algorithm.) -/ def sort (s : finset α) : list α := sort r s.1 @[simp] theorem sort_sorted (s : finset α) : list.sorted r (sort r s) := sort_sorted _ _ @[simp] theorem sort_eq (s : finset α) : ↑(sort r s) = s.1 := sort_eq _ _ @[simp] theorem sort_nodup (s : finset α) : (sort r s).nodup := (by rw sort_eq; exact s.2 : @multiset.nodup α (sort r s)) @[simp] theorem sort_to_finset [decidable_eq α] (s : finset α) : (sort r s).to_finset = s := list.to_finset_eq (sort_nodup r s) ▸ eq_of_veq (sort_eq r s) @[simp] theorem mem_sort {s : finset α} {a : α} : a ∈ sort r s ↔ a ∈ s := multiset.mem_sort _ @[simp] theorem length_sort {s : finset α} : (sort r s).length = s.card := multiset.length_sort _ end sort section sort_linear_order variables [decidable_linear_order α] theorem sort_sorted_lt (s : finset α) : list.sorted (<) (sort (≤) s) := (sort_sorted _ _).imp₂ (@lt_of_le_of_ne _ _) (sort_nodup _ _) lemma sorted_zero_eq_min' (s : finset α) (h : 0 < (s.sort (≤)).length) (H : s.nonempty) : (s.sort (≤)).nth_le 0 h = s.min' H := begin let l := s.sort (≤), apply le_antisymm, { have : s.min' H ∈ l := (finset.mem_sort (≤)).mpr (s.min'_mem H), obtain ⟨i, i_lt, hi⟩ : ∃ i (hi : i < l.length), l.nth_le i hi = s.min' H := list.mem_iff_nth_le.1 this, rw ← hi, exact list.nth_le_of_sorted_of_le (s.sort_sorted (≤)) (nat.zero_le i) }, { have : l.nth_le 0 h ∈ s := (finset.mem_sort (≤)).1 (list.nth_le_mem l 0 h), exact s.min'_le H _ this } end lemma sorted_last_eq_max' (s : finset α) (h : (s.sort (≤)).length - 1 < (s.sort (≤)).length) (H : s.nonempty) : (s.sort (≤)).nth_le ((s.sort (≤)).length - 1) h = s.max' H := begin let l := s.sort (≤), apply le_antisymm, { have : l.nth_le ((s.sort (≤)).length - 1) h ∈ s := (finset.mem_sort (≤)).1 (list.nth_le_mem l _ h), exact s.le_max' H _ this }, { have : s.max' H ∈ l := (finset.mem_sort (≤)).mpr (s.max'_mem H), obtain ⟨i, i_lt, hi⟩ : ∃ i (hi : i < l.length), l.nth_le i hi = s.max' H := list.mem_iff_nth_le.1 this, rw ← hi, have : i ≤ l.length - 1 := nat.le_pred_of_lt i_lt, exact list.nth_le_of_sorted_of_le (s.sort_sorted (≤)) (nat.le_pred_of_lt i_lt) }, end /-- Given a finset `s` of cardinal `k` in a linear order `α`, the map `mono_of_fin s h` is the increasing bijection between `fin k` and `s` as an `α`-valued map. Here, `h` is a proof that the cardinality of `s` is `k`. We use this instead of a map `fin s.card → α` to avoid casting issues in further uses of this function. -/ def mono_of_fin (s : finset α) {k : ℕ} (h : s.card = k) (i : fin k) : α := have A : (i : ℕ) < (s.sort (≤)).length, by simpa [h] using i.2, (s.sort (≤)).nth_le i A lemma bij_on_mono_of_fin (s : finset α) {k : ℕ} (h : s.card = k) : set.bij_on (s.mono_of_fin h) set.univ ↑s := begin have A : ∀ j, j ∈ s ↔ j ∈ (s.sort (≤)) := λ j, by simp, apply set.bij_on.mk, { assume i hi, simp only [mono_of_fin, set.mem_preimage, mem_coe, list.nth_le, A], exact list.nth_le_mem _ _ _ }, { refine (strict_mono.injective (λ i j hij, _)).inj_on _, exact list.pairwise_iff_nth_le.1 s.sort_sorted_lt _ _ _ hij }, { assume x hx, simp only [mem_coe, A] at hx, obtain ⟨i, il, hi⟩ : ∃ (i : ℕ) (h : i < (s.sort (≤)).length), (s.sort (≤)).nth_le i h = x := list.nth_le_of_mem hx, simp [h] at il, exact ⟨⟨i, il⟩, set.mem_univ _, hi⟩ } end /-- Given a finset `s` of cardinal `k` in a linear order `α`, the equiv `mono_equiv_of_fin s h` is the increasing bijection between `fin k` and `s` as an `s`-valued map. Here, `h` is a proof that the cardinality of `s` is `k`. We use this instead of a map `fin s.card → α` to avoid casting issues in further uses of this function. -/ noncomputable def mono_equiv_of_fin (s : finset α) {k : ℕ} (h : s.card = k) : fin k ≃ {x // x ∈ s} := (s.bij_on_mono_of_fin h).equiv _ end sort_linear_order /-! ### disjoint -/ section disjoint variable [decidable_eq α] theorem disjoint_left {s t : finset α} : disjoint s t ↔ ∀ {a}, a ∈ s → a ∉ t := by simp only [_root_.disjoint, inf_eq_inter, le_iff_subset, subset_iff, mem_inter, not_and, and_imp]; refl theorem disjoint_val {s t : finset α} : disjoint s t ↔ s.1.disjoint t.1 := disjoint_left theorem disjoint_iff_inter_eq_empty {s t : finset α} : disjoint s t ↔ s ∩ t = ∅ := disjoint_iff theorem disjoint_right {s t : finset α} : disjoint s t ↔ ∀ {a}, a ∈ t → a ∉ s := by rw [disjoint.comm, disjoint_left] theorem disjoint_iff_ne {s t : finset α} : disjoint s t ↔ ∀ a ∈ s, ∀ b ∈ t, a ≠ b := by simp only [disjoint_left, imp_not_comm, forall_eq'] theorem disjoint_of_subset_left {s t u : finset α} (h : s ⊆ u) (d : disjoint u t) : disjoint s t := disjoint_left.2 (λ x m₁, (disjoint_left.1 d) (h m₁)) theorem disjoint_of_subset_right {s t u : finset α} (h : t ⊆ u) (d : disjoint s u) : disjoint s t := disjoint_right.2 (λ x m₁, (disjoint_right.1 d) (h m₁)) @[simp] theorem disjoint_empty_left (s : finset α) : disjoint ∅ s := disjoint_bot_left @[simp] theorem disjoint_empty_right (s : finset α) : disjoint s ∅ := disjoint_bot_right @[simp] theorem singleton_disjoint {s : finset α} {a : α} : disjoint (singleton a) s ↔ a ∉ s := by simp only [disjoint_left, mem_singleton, forall_eq] @[simp] theorem disjoint_singleton {s : finset α} {a : α} : disjoint s (singleton a) ↔ a ∉ s := disjoint.comm.trans singleton_disjoint @[simp] theorem disjoint_insert_left {a : α} {s t : finset α} : disjoint (insert a s) t ↔ a ∉ t ∧ disjoint s t := by simp only [disjoint_left, mem_insert, or_imp_distrib, forall_and_distrib, forall_eq] @[simp] theorem disjoint_insert_right {a : α} {s t : finset α} : disjoint s (insert a t) ↔ a ∉ s ∧ disjoint s t := disjoint.comm.trans $ by rw [disjoint_insert_left, disjoint.comm] @[simp] theorem disjoint_union_left {s t u : finset α} : disjoint (s ∪ t) u ↔ disjoint s u ∧ disjoint t u := by simp only [disjoint_left, mem_union, or_imp_distrib, forall_and_distrib] @[simp] theorem disjoint_union_right {s t u : finset α} : disjoint s (t ∪ u) ↔ disjoint s t ∧ disjoint s u := by simp only [disjoint_right, mem_union, or_imp_distrib, forall_and_distrib] lemma sdiff_disjoint {s t : finset α} : disjoint (t \ s) s := disjoint_left.2 $ assume a ha, (mem_sdiff.1 ha).2 lemma disjoint_sdiff {s t : finset α} : disjoint s (t \ s) := sdiff_disjoint.symm lemma disjoint_bind_left {ι : Type*} [decidable_eq ι] (s : finset ι) (f : ι → finset α) (t : finset α) : disjoint (s.bind f) t ↔ (∀i∈s, disjoint (f i) t) := begin refine s.induction _ _, { simp only [forall_mem_empty_iff, bind_empty, disjoint_empty_left] }, { assume i s his ih, simp only [disjoint_union_left, bind_insert, his, forall_mem_insert, ih] } end lemma disjoint_bind_right {ι : Type*} [decidable_eq ι] (s : finset α) (t : finset ι) (f : ι → finset α) : disjoint s (t.bind f) ↔ (∀i∈t, disjoint s (f i)) := by simpa only [disjoint.comm] using disjoint_bind_left t f s @[simp] theorem card_disjoint_union {s t : finset α} (h : disjoint s t) : card (s ∪ t) = card s + card t := by rw [← card_union_add_card_inter, disjoint_iff_inter_eq_empty.1 h, card_empty, add_zero] theorem card_sdiff {s t : finset α} (h : s ⊆ t) : card (t \ s) = card t - card s := suffices card (t \ s) = card ((t \ s) ∪ s) - card s, by rwa sdiff_union_of_subset h at this, by rw [card_disjoint_union sdiff_disjoint, nat.add_sub_cancel] lemma disjoint_filter {s : finset α} {p q : α → Prop} [decidable_pred p] [decidable_pred q] : disjoint (s.filter p) (s.filter q) ↔ (∀ x ∈ s, p x → ¬ q x) := by split; simp [disjoint_left] {contextual := tt} lemma pi_disjoint_of_disjoint {δ : α → Type*} [∀a, decidable_eq (δ a)] {s : finset α} [decidable_eq (Πa∈s, δ a)] (t₁ t₂ : Πa, finset (δ a)) {a : α} (ha : a ∈ s) (h : disjoint (t₁ a) (t₂ a)) : disjoint (s.pi t₁) (s.pi t₂) := disjoint_iff_ne.2 $ λ f₁ hf₁ f₂ hf₂ eq₁₂, disjoint_iff_ne.1 h (f₁ a ha) (mem_pi.mp hf₁ a ha) (f₂ a ha) (mem_pi.mp hf₂ a ha) $ congr_fun (congr_fun eq₁₂ a) ha end disjoint instance [has_repr α] : has_repr (finset α) := ⟨λ s, repr s.1⟩ /-- Given a finset `s` of `ℕ` contained in `{0,..., n-1}`, the corresponding finset in `fin n` is `s.attach_fin h` where `h` is a proof that all elements of `s` are less than `n`. -/ def attach_fin (s : finset ℕ) {n : ℕ} (h : ∀ m ∈ s, m < n) : finset (fin n) := ⟨s.1.pmap (λ a ha, ⟨a, ha⟩) h, multiset.nodup_pmap (λ _ _ _ _, fin.mk.inj) s.2⟩ @[simp] lemma mem_attach_fin {n : ℕ} {s : finset ℕ} (h : ∀ m ∈ s, m < n) {a : fin n} : a ∈ s.attach_fin h ↔ a.1 ∈ s := ⟨λ h, let ⟨b, hb₁, hb₂⟩ := multiset.mem_pmap.1 h in hb₂ ▸ hb₁, λ h, multiset.mem_pmap.2 ⟨a.1, h, fin.eta _ _⟩⟩ @[simp] lemma card_attach_fin {n : ℕ} (s : finset ℕ) (h : ∀ m ∈ s, m < n) : (s.attach_fin h).card = s.card := multiset.card_pmap _ _ _ /-! ### choose -/ section choose variables (p : α → Prop) [decidable_pred p] (l : finset α) /-- Given a finset `l` and a predicate `p`, associate to a proof that there is a unique element of `l` satisfying `p` this unique element, as an element of the corresponding subtype. -/ def choose_x (hp : (∃! a, a ∈ l ∧ p a)) : { a // a ∈ l ∧ p a } := multiset.choose_x p l.val hp /-- Given a finset `l` and a predicate `p`, associate to a proof that there is a unique element of `l` satisfying `p` this unique element, as an element of the ambient type. -/ def choose (hp : ∃! a, a ∈ l ∧ p a) : α := choose_x p l hp lemma choose_spec (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) := (choose_x p l hp).property lemma choose_mem (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l := (choose_spec _ _ _).1 lemma choose_property (hp : ∃! a, a ∈ l ∧ p a) : p (choose p l hp) := (choose_spec _ _ _).2 end choose theorem lt_wf {α} : well_founded (@has_lt.lt (finset α) _) := have H : subrelation (@has_lt.lt (finset α) _) (inv_image (<) card), from λ x y hxy, card_lt_card hxy, subrelation.wf H $ inv_image.wf _ $ nat.lt_wf section decidable_linear_order variables {α} [decidable_linear_order α] end decidable_linear_order /-! ### intervals -/ /- Ico (a closed open interval) -/ variables {n m l : ℕ} /-- `Ico n m` is the set of natural numbers `n ≤ k < m`. -/ def Ico (n m : ℕ) : finset ℕ := ⟨_, Ico.nodup n m⟩ namespace Ico @[simp] theorem val (n m : ℕ) : (Ico n m).1 = multiset.Ico n m := rfl @[simp] theorem to_finset (n m : ℕ) : (multiset.Ico n m).to_finset = Ico n m := (multiset.to_finset_eq _).symm theorem image_add (n m k : ℕ) : (Ico n m).image ((+) k) = Ico (n + k) (m + k) := by simp [image, multiset.Ico.map_add] theorem image_sub (n m k : ℕ) (h : k ≤ n) : (Ico n m).image (λ x, x - k) = Ico (n - k) (m - k) := begin dsimp [image], rw [multiset.Ico.map_sub _ _ _ h, ←multiset.to_finset_eq], refl, end theorem zero_bot (n : ℕ) : Ico 0 n = range n := eq_of_veq $ multiset.Ico.zero_bot _ @[simp] theorem card (n m : ℕ) : (Ico n m).card = m - n := multiset.Ico.card _ _ @[simp] theorem mem {n m l : ℕ} : l ∈ Ico n m ↔ n ≤ l ∧ l < m := multiset.Ico.mem theorem eq_empty_of_le {n m : ℕ} (h : m ≤ n) : Ico n m = ∅ := eq_of_veq $ multiset.Ico.eq_zero_of_le h @[simp] theorem self_eq_empty (n : ℕ) : Ico n n = ∅ := eq_empty_of_le $ le_refl n @[simp] theorem eq_empty_iff {n m : ℕ} : Ico n m = ∅ ↔ m ≤ n := iff.trans val_eq_zero.symm multiset.Ico.eq_zero_iff theorem subset_iff {m₁ n₁ m₂ n₂ : ℕ} (hmn : m₁ < n₁) : Ico m₁ n₁ ⊆ Ico m₂ n₂ ↔ (m₂ ≤ m₁ ∧ n₁ ≤ n₂) := begin simp only [subset_iff, mem], refine ⟨λ h, ⟨_, _⟩, _⟩, { exact (h ⟨le_refl _, hmn⟩).1 }, { refine le_of_pred_lt (@h (pred n₁) ⟨le_pred_of_lt hmn, pred_lt _⟩).2, exact ne_of_gt (lt_of_le_of_lt (nat.zero_le m₁) hmn) }, { rintros ⟨hm, hn⟩ k ⟨hmk, hkn⟩, exact ⟨le_trans hm hmk, lt_of_lt_of_le hkn hn⟩ } end protected theorem subset {m₁ n₁ m₂ n₂ : ℕ} (hmm : m₂ ≤ m₁) (hnn : n₁ ≤ n₂) : Ico m₁ n₁ ⊆ Ico m₂ n₂ := begin simp only [finset.subset_iff, Ico.mem], assume x hx, exact ⟨le_trans hmm hx.1, lt_of_lt_of_le hx.2 hnn⟩ end lemma union_consecutive {n m l : ℕ} (hnm : n ≤ m) (hml : m ≤ l) : Ico n m ∪ Ico m l = Ico n l := by rw [← to_finset, ← to_finset, ← multiset.to_finset_add, multiset.Ico.add_consecutive hnm hml, to_finset] @[simp] lemma inter_consecutive (n m l : ℕ) : Ico n m ∩ Ico m l = ∅ := begin rw [← to_finset, ← to_finset, ← multiset.to_finset_inter, multiset.Ico.inter_consecutive], simp, end lemma disjoint_consecutive (n m l : ℕ) : disjoint (Ico n m) (Ico m l) := le_of_eq $ inter_consecutive n m l @[simp] theorem succ_singleton (n : ℕ) : Ico n (n+1) = {n} := eq_of_veq $ multiset.Ico.succ_singleton theorem succ_top {n m : ℕ} (h : n ≤ m) : Ico n (m + 1) = insert m (Ico n m) := by rw [← to_finset, multiset.Ico.succ_top h, multiset.to_finset_cons, to_finset] theorem succ_top' {n m : ℕ} (h : n < m) : Ico n m = insert (m - 1) (Ico n (m - 1)) := begin have w : m = m - 1 + 1 := (nat.sub_add_cancel (nat.one_le_of_lt h)).symm, conv { to_lhs, rw w }, rw succ_top, exact nat.le_pred_of_lt h end theorem insert_succ_bot {n m : ℕ} (h : n < m) : insert n (Ico (n + 1) m) = Ico n m := by rw [eq_comm, ← to_finset, multiset.Ico.eq_cons h, multiset.to_finset_cons, to_finset] @[simp] theorem pred_singleton {m : ℕ} (h : 0 < m) : Ico (m - 1) m = {m - 1} := eq_of_veq $ multiset.Ico.pred_singleton h @[simp] theorem not_mem_top {n m : ℕ} : m ∉ Ico n m := multiset.Ico.not_mem_top lemma filter_lt_of_top_le {n m l : ℕ} (hml : m ≤ l) : (Ico n m).filter (λ x, x < l) = Ico n m := eq_of_veq $ multiset.Ico.filter_lt_of_top_le hml lemma filter_lt_of_le_bot {n m l : ℕ} (hln : l ≤ n) : (Ico n m).filter (λ x, x < l) = ∅ := eq_of_veq $ multiset.Ico.filter_lt_of_le_bot hln lemma filter_lt_of_ge {n m l : ℕ} (hlm : l ≤ m) : (Ico n m).filter (λ x, x < l) = Ico n l := eq_of_veq $ multiset.Ico.filter_lt_of_ge hlm @[simp] lemma filter_lt (n m l : ℕ) : (Ico n m).filter (λ x, x < l) = Ico n (min m l) := eq_of_veq $ multiset.Ico.filter_lt n m l lemma filter_le_of_le_bot {n m l : ℕ} (hln : l ≤ n) : (Ico n m).filter (λ x, l ≤ x) = Ico n m := eq_of_veq $ multiset.Ico.filter_le_of_le_bot hln lemma filter_le_of_top_le {n m l : ℕ} (hml : m ≤ l) : (Ico n m).filter (λ x, l ≤ x) = ∅ := eq_of_veq $ multiset.Ico.filter_le_of_top_le hml lemma filter_le_of_le {n m l : ℕ} (hnl : n ≤ l) : (Ico n m).filter (λ x, l ≤ x) = Ico l m := eq_of_veq $ multiset.Ico.filter_le_of_le hnl @[simp] lemma filter_le (n m l : ℕ) : (Ico n m).filter (λ x, l ≤ x) = Ico (max n l) m := eq_of_veq $ multiset.Ico.filter_le n m l @[simp] lemma diff_left (l n m : ℕ) : (Ico n m) \ (Ico n l) = Ico (max n l) m := by ext k; by_cases n ≤ k; simp [h, and_comm] @[simp] lemma diff_right (l n m : ℕ) : (Ico n m) \ (Ico l m) = Ico n (min m l) := have ∀k, (k < m ∧ (l ≤ k → m ≤ k)) ↔ (k < m ∧ k < l) := assume k, and_congr_right $ assume hk, by rw [← not_imp_not]; simp [hk], by ext k; by_cases n ≤ k; simp [h, this] end Ico -- TODO We don't yet attempt to reproduce the entire interface for `Ico` for `Ico_ℤ`. /-- `Ico_ℤ l u` is the set of integers `l ≤ k < u`. -/ def Ico_ℤ (l u : ℤ) : finset ℤ := (finset.range (u - l).to_nat).map { to_fun := λ n, n + l, inj := λ n m h, by simpa using h } @[simp] lemma Ico_ℤ.mem {n m l : ℤ} : l ∈ Ico_ℤ n m ↔ n ≤ l ∧ l < m := begin dsimp [Ico_ℤ], simp only [int.lt_to_nat, exists_prop, mem_range, add_comm, function.embedding.coe_fn_mk, mem_map], split, { rintro ⟨a, ⟨h, rfl⟩⟩, exact ⟨int.le.intro rfl, lt_sub_iff_add_lt'.mp h⟩ }, { rintro ⟨h₁, h₂⟩, use (l - n).to_nat, split; simp [h₁, h₂], } end @[simp] lemma Ico_ℤ.card (l u : ℤ) : (Ico_ℤ l u).card = (u - l).to_nat := by simp [Ico_ℤ] end finset namespace multiset lemma count_sup [decidable_eq β] (s : finset α) (f : α → multiset β) (b : β) : count b (s.sup f) = s.sup (λa, count b (f a)) := begin letI := classical.dec_eq α, refine s.induction _ _, { exact count_zero _ }, { assume i s his ih, rw [finset.sup_insert, sup_eq_union, count_union, finset.sup_insert, ih], refl } end end multiset namespace list variable [decidable_eq α] theorem to_finset_card_of_nodup {l : list α} (h : l.nodup) : l.to_finset.card = l.length := congr_arg card $ (@multiset.erase_dup_eq_self α _ l).2 h end list section lattice variables {ι : Sort*} [complete_lattice α] [decidable_eq ι] lemma supr_eq_supr_finset (s : ι → α) : (⨆i, s i) = (⨆t:finset (plift ι), ⨆i∈t, s (plift.down i)) := le_antisymm (supr_le $ assume b, le_supr_of_le {plift.up b} $ le_supr_of_le (plift.up b) $ le_supr_of_le (by simp) $ le_refl _) (supr_le $ assume t, supr_le $ assume b, supr_le $ assume hb, le_supr _ _) lemma infi_eq_infi_finset (s : ι → α) : (⨅i, s i) = (⨅t:finset (plift ι), ⨅i∈t, s (plift.down i)) := le_antisymm (le_infi $ assume t, le_infi $ assume b, le_infi $ assume hb, infi_le _ _) (le_infi $ assume b, infi_le_of_le {plift.up b} $ infi_le_of_le (plift.up b) $ infi_le_of_le (by simp) $ le_refl _) end lattice namespace set variables {ι : Sort*} [decidable_eq ι] lemma Union_eq_Union_finset (s : ι → set α) : (⋃i, s i) = (⋃t:finset (plift ι), ⋃i∈t, s (plift.down i)) := supr_eq_supr_finset s lemma Inter_eq_Inter_finset (s : ι → set α) : (⋂i, s i) = (⋂t:finset (plift ι), ⋂i∈t, s (plift.down i)) := infi_eq_infi_finset s end set 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).to_finset /-- 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, multiset.mem_to_finset, 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 simpa using list.to_finset_card_of_nodup (list.nat.nodup_antidiagonal n) /-- The antidiagonal of `0` is the list `[(0,0)]` -/ @[simp] lemma antidiagonal_zero : antidiagonal 0 = {(0, 0)} := by { rw [antidiagonal, multiset.nat.antidiagonal_zero], refl } end nat end finset namespace finset /-! ### bUnion -/ variables [decidable_eq α] @[simp] theorem bUnion_singleton (a : α) (s : α → set β) : (⋃ x ∈ ({a} : finset α), s x) = s a := supr_singleton theorem supr_union {α} [complete_lattice α] {β} [decidable_eq β] {f : β → α} {s t : finset β} : (⨆ x ∈ s ∪ t, f x) = (⨆x∈s, f x) ⊔ (⨆x∈t, f x) := calc (⨆ x ∈ s ∪ t, f x) = (⨆ x, (⨆h : x∈s, f x) ⊔ (⨆h : x∈t, f x)) : congr_arg _ $ funext $ λ x, by { convert supr_or, rw finset.mem_union, rw finset.mem_union, refl, refl } ... = (⨆x∈s, f x) ⊔ (⨆x∈t, f x) : supr_sup_eq lemma bUnion_union (s t : finset α) (u : α → set β) : (⋃ x ∈ s ∪ t, u x) = (⋃ x ∈ s, u x) ∪ (⋃ x ∈ t, u x) := supr_union @[simp] lemma bUnion_insert (a : α) (s : finset α) (t : α → set β) : (⋃ x ∈ insert a s, t x) = t a ∪ (⋃ x ∈ s, t x) := begin rw insert_eq, simp only [bUnion_union, finset.bUnion_singleton] end end finset
80734fad982d5b9f469fbcd0824e122955bd67e9
d450724ba99f5b50b57d244eb41fef9f6789db81
/src/instructor/lectures/lecture_15.lean
eae8b3153e96bc0d85aaf88be7392ab2ef6670ab
[]
no_license
jakekauff/CS2120F21
4f009adeb4ce4a148442b562196d66cc6c04530c
e69529ec6f5d47a554291c4241a3d8ec4fe8f5ad
refs/heads/main
1,693,841,880,030
1,637,604,848,000
1,637,604,848,000
399,946,698
0
0
null
null
null
null
UTF-8
Lean
false
false
5,765
lean
/- This lecture extends what you have learned by introducing the concept that existential quantification is an "information hiding" abstraction mechanism. To build a proof of ∃ x, P x, you have to give a specific value for x; but when you eliminate from a proof of ∃ x, P x, all you get is some arbitrary but specific value (aka general) value, along with a proof that that value has the stated property, P. The specific value that was presumably used to build the proof is no longer available. It has been abstracted away, and elimination is not able to recover it. -/ /- Let's see this idea in action. We'll represent a *property* objects of a type, α, as a *predicate* on α values. (Using α is cooler than using T as a type valued variable.) Here we'll juse use our simple evenness one-place predicate on natural numbers. It is satisfied by any natural number, n, such that n % 2 is zero. -/ def ev (n : ℕ) : Prop := n % 2 = 0 #check ev -- predicate: nat → Prop /- Here we'll formalize and prove a simple theorem that says that if you assume (or are given) (1) a natural number, n, and (2), a proof, pf, of (ev n), then you can prove ∃ n, ev n: that *there exists* an even natural number. You do it of course by applying the introduction rule for exists to n as a witness and pf as the corresponding required proof. The main point of this example is just to remind you exactly how exists.intro works. -/ theorem ex_ev_n (n : ℕ) (pf : ev n) : ∃ (m : ℕ), ev m := ⟨ n, pf ⟩ -- exists.intro n pf /- Ok, great, so now what can we do with such a theorem? Well, this particular is a universal generalization, in the sense that it takes any natural number and any corresponding proof that that *particular* number is even and gives you something else in return, a proof of ∃ n, ev n. Here, for example, is a proof that there exists an even number with 4 as a witness. -/ #check ex_ev_n 4 rfl def pf_ex : ∃ (n : ℕ), ev n := ex_ev_n 4 rfl /- Four happens to be the witness used to build a proof of ∃ x, ev x, in this case; but from this proof one can no longer recover that 4. Existential proofs "abstract away" the values used to construct them. In particular, one doesn't say, "There exists an x that satisfies P, and here is one, w, along with a proof that it does satisfy P. Rather such a proof just says, "There is some x with property, P and can't say any more than that." -/ /- Now let's look at an example using Lean. In this example we set ou to prove (∃ x, P x -> true) so that we can assume (get into our context a proof of) ∃ x, P x. Our aim isn't to prove true, but to see exactly what we can do with a such a proof. The answer is that we can "eliminate" it to get (1) an arbitrary but specific (general) value *with a name, such as w*, along with a proof that that w has property P: a proof of (P w). -/ example : (∃ (m : ℕ), ev m) → true := begin assume h, -- get ourselves proof of ∃ cases h with w pf, -- what case analysis does: -- one intro rule, one case, -- with info about the args, -- but no witness *details*. trivial, end /- As you now already kno, the cases tactic applies the elimination rule for the given form of value. So, here, it applies or.elim (and a few clean-up tactics). Put your cursor at the end of the cases line and study the resulting context. You now have a witness, w, of the right type, but you do *not* have a specific value. You just have an arbitrary value, albeit with a proof that it has the given property. -/ /- The constraint that the elimination rule doesn't reveal the witness, once it has been abstracted away, is enforced by Lean's type system. Let's see what happen if we try to recover the natural number, m, "inside" a proof of (∃ (m : ℕ), ev m). Notice the crucial difference in the type of the following implication/function. Whereas above we wanted a proof of (∃ (m : ℕ), ev m) → true, a purely logical proposition, how we're trying to produce a proof of (∃ (m : ℕ), ev m) → nat. In other words, we're trying to define a function that takes a proof of an existential proposition as an argument and that somehow then derives a natural number from it. You might think that the original witness is preserved in the proof, but it's not. Again, that information is abstracted away. Fortunately, Lean complains that you are "trying to eliminate from a proof to a value of a type, T," where T is not Prop. What Lean is really saying is that you may not derive data values from proofs. This restriction is part of Lean's approach to assuring the principle of "proof irrelevance." Any proof is as good as any other, and equivalent in all respects. If we could get 4 from one ∃ proof and 5 from another, then this principle would break: we'd be able to tell the proofs apart, which our logic cannot let us do. -/ example : (∃ (m : ℕ), ev m) → nat := begin assume h, -- get ourselves proof of ∃ cases h with w pf, -- here's where you get caught end /- What Lean is saying is that it's alright from a proof of (∃ (m : ℕ), ev m) to derive a proof of true, because true lives in the type, Prop. On the other hand, nat lives in the type, Type, and the rules of predicate logic do not allow one to recover a computationally relevant value from a proof of ∃ x, P. (I'm dropping the P x notation.) In this way Lean enforces the abstracting nature of existential quantification. Think about that and try to really understand what it means. The concept of information hiding abstraction is at the heart of mathematics and programming. Here you see a particularly simple exampe of it. -/
25d97151620a03445ca98190a3f6b40503d62918
8e6cad62ec62c6c348e5faaa3c3f2079012bdd69
/src/linear_algebra/direct_sum_module.lean
9d917af152a8efc1793d405035023961bf0ecdb4
[ "Apache-2.0" ]
permissive
benjamindavidson/mathlib
8cc81c865aa8e7cf4462245f58d35ae9a56b150d
fad44b9f670670d87c8e25ff9cdf63af87ad731e
refs/heads/master
1,679,545,578,362
1,615,343,014,000
1,615,343,014,000
312,926,983
0
0
Apache-2.0
1,615,360,301,000
1,605,399,418,000
Lean
UTF-8
Lean
false
false
4,762
lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau Direct sum of modules over commutative rings, indexed by a discrete type. -/ import algebra.direct_sum import linear_algebra.dfinsupp /-! # Direct sum of modules over commutative rings, indexed by a discrete type. This file provides constructors for finite direct sums of modules. It provides a construction of the direct sum using the universal property and proves its uniqueness. ## Implementation notes All of this file assumes that * `R` is a commutative ring, * `ι` is a discrete type, * `S` is a finite set in `ι`, * `M` is a family of `R` semimodules indexed over `ι`. -/ universes u v w u₁ variables (R : Type u) [semiring R] variables (ι : Type v) [dec_ι : decidable_eq ι] (M : ι → Type w) variables [Π i, add_comm_monoid (M i)] [Π i, semimodule R (M i)] include R namespace direct_sum open_locale direct_sum variables {R ι M} instance : semimodule R (⨁ i, M i) := dfinsupp.semimodule lemma smul_apply (b : R) (v : ⨁ i, M i) (i : ι) : (b • v) i = b • (v i) := dfinsupp.smul_apply _ _ _ include dec_ι variables R ι M /-- Create the direct sum given a family `M` of `R` semimodules indexed over `ι`. -/ def lmk : Π s : finset ι, (Π i : (↑s : set ι), M i.val) →ₗ[R] (⨁ i, M i) := dfinsupp.lmk /-- Inclusion of each component into the direct sum. -/ def lof : Π i : ι, M i →ₗ[R] (⨁ i, M i) := dfinsupp.lsingle variables {ι M} lemma single_eq_lof (i : ι) (b : M i) : dfinsupp.single i b = lof R ι M i b := rfl /-- Scalar multiplication commutes with direct sums. -/ theorem mk_smul (s : finset ι) (c : R) (x) : mk M s (c • x) = c • mk M s x := (lmk R ι M s).map_smul c x /-- Scalar multiplication commutes with the inclusion of each component into the direct sum. -/ theorem of_smul (i : ι) (c : R) (x) : of M i (c • x) = c • of M i x := (lof R ι M i).map_smul c x variables {R} lemma support_smul [Π (i : ι) (x : M i), decidable (x ≠ 0)] (c : R) (v : ⨁ i, M i) : (c • v).support ⊆ v.support := dfinsupp.support_smul _ _ variables {N : Type u₁} [add_comm_monoid N] [semimodule R N] variables (φ : Π i, M i →ₗ[R] N) variables (R ι N φ) /-- The linear map constructed using the universal property of the coproduct. -/ def to_module : (⨁ i, M i) →ₗ[R] N := dfinsupp.lsum ℕ φ variables {ι N φ} /-- The map constructed using the universal property gives back the original maps when restricted to each component. -/ @[simp] lemma to_module_lof (i) (x : M i) : to_module R ι N φ (lof R ι M i x) = φ i x := to_add_monoid_of (λ i, (φ i).to_add_monoid_hom) i x variables (ψ : (⨁ i, M i) →ₗ[R] N) /-- Every linear map from a direct sum agrees with the one obtained by applying the universal property to each of its components. -/ theorem to_module.unique (f : ⨁ i, M i) : ψ f = to_module R ι N (λ i, ψ.comp $ lof R ι M i) f := to_add_monoid.unique ψ.to_add_monoid_hom f variables {ψ} {ψ' : (⨁ i, M i) →ₗ[R] N} theorem to_module.ext (H : ∀ i, ψ.comp (lof R ι M i) = ψ'.comp (lof R ι M i)) (f : ⨁ i, M i) : ψ f = ψ' f := by rw dfinsupp.lhom_ext' H /-- The inclusion of a subset of the direct summands into a larger subset of the direct summands, as a linear map. -/ def lset_to_set (S T : set ι) (H : S ⊆ T) : (⨁ (i : S), M i) →ₗ (⨁ (i : T), M i) := to_module R _ _ $ λ i, lof R T (λ (i : subtype T), M i) ⟨i, H i.prop⟩ omit dec_ι /-- The natural linear equivalence between `⨁ _ : ι, M` and `M` when `unique ι`. -/ protected def lid (M : Type v) (ι : Type* := punit) [add_comm_monoid M] [semimodule R M] [unique ι] : (⨁ (_ : ι), M) ≃ₗ M := { .. direct_sum.id M ι, .. to_module R ι M (λ i, linear_map.id) } variables (ι M) /-- The projection map onto one component, as a linear map. -/ def component (i : ι) : (⨁ i, M i) →ₗ[R] M i := dfinsupp.lapply i variables {ι M} lemma apply_eq_component (f : ⨁ i, M i) (i : ι) : f i = component R ι M i f := rfl @[ext] lemma ext {f g : ⨁ i, M i} (h : ∀ i, component R ι M i f = component R ι M i g) : f = g := dfinsupp.ext h lemma ext_iff {f g : ⨁ i, M i} : f = g ↔ ∀ i, component R ι M i f = component R ι M i g := ⟨λ h _, by rw h, ext R⟩ include dec_ι @[simp] lemma lof_apply (i : ι) (b : M i) : ((lof R ι M i) b) i = b := dfinsupp.single_eq_same @[simp] lemma component.lof_self (i : ι) (b : M i) : component R ι M i ((lof R ι M i) b) = b := lof_apply R i b lemma component.of (i j : ι) (b : M j) : component R ι M i ((lof R ι M j) b) = if h : j = i then eq.rec_on h b else 0 := dfinsupp.single_apply end direct_sum
0bcc91072204ce69ed851a5595262dfe2a80b285
624f6f2ae8b3b1adc5f8f67a365c51d5126be45a
/stage0/src/Init/Lean/Compiler/IR/UnboxResult.lean
818008c6f87493c5add3e0077704ed2e8a7bbde6
[ "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
960
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.Lean.Data.Format import Init.Lean.Compiler.IR.Basic namespace Lean namespace IR namespace UnboxResult def mkUnboxAttr : IO TagAttribute := registerTagAttribute `unbox "compiler tries to unbox result values if their types are tagged with `[unbox]`" $ fun env declName => match env.find? declName with | none => Except.error "unknown declaration" | some cinfo => match cinfo with | ConstantInfo.inductInfo v => if v.isRec then Except.error "recursive inductive datatypes are not supported" else Except.ok () | _ => Except.error "constant must be an inductive type" @[init mkUnboxAttr] constant unboxAttr : TagAttribute := arbitrary _ def hasUnboxAttr (env : Environment) (n : Name) : Bool := unboxAttr.hasTag env n end UnboxResult end IR end Lean
b85fe0d0ca66e35d300f3c0e6dd2dfe600340184
9b9a16fa2cb737daee6b2785474678b6fa91d6d4
/src/data/quot.lean
9de1c3b8a39ba25f18c285e171effa8d28fb0a96
[ "Apache-2.0" ]
permissive
johoelzl/mathlib
253f46daa30b644d011e8e119025b01ad69735c4
592e3c7a2dfbd5826919b4605559d35d4d75938f
refs/heads/master
1,625,657,216,488
1,551,374,946,000
1,551,374,946,000
98,915,829
0
0
Apache-2.0
1,522,917,267,000
1,501,524,499,000
Lean
UTF-8
Lean
false
false
10,061
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 Quotients -- extends the core library -/ variables {α : Sort*} {β : Sort*} namespace setoid lemma ext {α : Sort*} : ∀{s t : setoid α}, (∀a b, @setoid.r α s a b ↔ @setoid.r α t a b) → s = t | ⟨r, _⟩ ⟨p, _⟩ eq := have r = p, from funext $ assume a, funext $ assume b, propext $ eq a b, by subst this end setoid namespace quot variables {ra : α → α → Prop} {rb : β → β → Prop} {φ : quot ra → quot rb → Sort*} local notation `⟦`:max a `⟧` := quot.mk _ a protected def hrec_on₂ (qa : quot ra) (qb : quot rb) (f : ∀ a b, φ ⟦a⟧ ⟦b⟧) (ca : ∀ {b a₁ a₂}, ra a₁ a₂ → f a₁ b == f a₂ b) (cb : ∀ {a b₁ b₂}, rb b₁ b₂ → f a b₁ == f a b₂) : φ qa qb := quot.hrec_on qa (λ a, quot.hrec_on qb (f a) (λ b₁ b₂ pb, cb pb)) $ λ a₁ a₂ pa, quot.induction_on qb $ λ b, calc @quot.hrec_on _ _ (φ _) ⟦b⟧ (f a₁) (@cb _) == f a₁ b : by simp ... == f a₂ b : ca pa ... == @quot.hrec_on _ _ (φ _) ⟦b⟧ (f a₂) (@cb _) : by simp end quot namespace quotient variables [sa : setoid α] [sb : setoid β] variables {φ : quotient sa → quotient sb → Sort*} protected def hrec_on₂ (qa : quotient sa) (qb : quotient sb) (f : ∀ a b, φ ⟦a⟧ ⟦b⟧) (c : ∀ a₁ b₁ a₂ b₂, a₁ ≈ a₂ → b₁ ≈ b₂ → f a₁ b₁ == f a₂ b₂) : φ qa qb := quot.hrec_on₂ qa qb f (λ _ _ _ p, c _ _ _ _ p (setoid.refl _)) (λ _ _ _ p, c _ _ _ _ (setoid.refl _) p) end quotient @[simp] theorem quotient.eq [r : setoid α] {x y : α} : ⟦x⟧ = ⟦y⟧ ↔ x ≈ y := ⟨quotient.exact, quotient.sound⟩ theorem forall_quotient_iff {α : Type*} [r : setoid α] {p : quotient r → Prop} : (∀a:quotient r, p a) ↔ (∀a:α, p ⟦a⟧) := ⟨assume h x, h _, assume h a, a.induction_on h⟩ @[simp] lemma quotient.lift_beta [s : setoid α] (f : α → β) (h : ∀ (a b : α), a ≈ b → f a = f b) (x : α): quotient.lift f h (quotient.mk x) = f x := rfl @[simp] lemma quotient.lift_on_beta [s : setoid α] (f : α → β) (h : ∀ (a b : α), a ≈ b → f a = f b) (x : α): quotient.lift_on (quotient.mk x) f h = f x := rfl /-- Choose an element of the equivalence class using the axiom of choice. Sound but noncomputable. -/ noncomputable def quot.out {r : α → α → Prop} (q : quot r) : α := classical.some (quot.exists_rep q) /-- Unwrap the VM representation of a quotient to obtain an element of the equivalence class. Computable but unsound. -/ meta def quot.unquot {r : α → α → Prop} : quot r → α := unchecked_cast @[simp] theorem quot.out_eq {r : α → α → Prop} (q : quot r) : quot.mk r q.out = q := classical.some_spec (quot.exists_rep q) /-- Choose an element of the equivalence class using the axiom of choice. Sound but noncomputable. -/ noncomputable def quotient.out [s : setoid α] : quotient s → α := quot.out @[simp] theorem quotient.out_eq [s : setoid α] (q : quotient s) : ⟦q.out⟧ = q := q.out_eq theorem quotient.mk_out [s : setoid α] (a : α) : ⟦a⟧.out ≈ a := quotient.exact (quotient.out_eq _) instance pi_setoid {ι : Sort*} {α : ι → Sort*} [∀ i, setoid (α i)] : setoid (Π i, α i) := { r := λ a b, ∀ i, a i ≈ b i, iseqv := ⟨ λ a i, setoid.refl _, λ a b h i, setoid.symm (h _), λ a b c h₁ h₂ i, setoid.trans (h₁ _) (h₂ _)⟩ } noncomputable def quotient.choice {ι : Type*} {α : ι → Type*} [S : ∀ i, setoid (α i)] (f : ∀ i, quotient (S i)) : @quotient (Π i, α i) (by apply_instance) := ⟦λ i, (f i).out⟧ theorem quotient.choice_eq {ι : Type*} {α : ι → Type*} [∀ i, setoid (α i)] (f : ∀ i, α i) : quotient.choice (λ i, ⟦f i⟧) = ⟦f⟧ := quotient.sound $ λ i, quotient.mk_out _ lemma nonempty_quotient_iff (s : setoid α): nonempty (quotient s) ↔ nonempty α := ⟨assume ⟨a⟩, quotient.induction_on a nonempty.intro, assume ⟨a⟩, ⟨⟦a⟧⟩⟩ /-- `trunc α` is the quotient of `α` by the always-true relation. This is related to the propositional truncation in HoTT, and is similar in effect to `nonempty α`, but unlike `nonempty α`, `trunc α` is data, so the VM representation is the same as `α`, and so this can be used to maintain computability. -/ def {u} trunc (α : Sort u) : Sort u := @quot α (λ _ _, true) theorem true_equivalence : @equivalence α (λ _ _, true) := ⟨λ _, trivial, λ _ _ _, trivial, λ _ _ _ _ _, trivial⟩ namespace trunc /-- Constructor for `trunc α` -/ def mk (a : α) : trunc α := quot.mk _ a /-- Any constant function lifts to a function out of the truncation -/ def lift (f : α → β) (c : ∀ a b : α, f a = f b) : trunc α → β := quot.lift f (λ a b _, c a b) theorem ind {β : trunc α → Prop} : (∀ a : α, β (mk a)) → ∀ q : trunc α, β q := quot.ind protected theorem lift_beta (f : α → β) (c) (a : α) : lift f c (mk a) = f a := rfl @[reducible, elab_as_eliminator] protected def lift_on (q : trunc α) (f : α → β) (c : ∀ a b : α, f a = f b) : β := lift f c q @[elab_as_eliminator] protected theorem induction_on {β : trunc α → Prop} (q : trunc α) (h : ∀ a, β (mk a)) : β q := ind h q theorem exists_rep (q : trunc α) : ∃ a : α, mk a = q := quot.exists_rep q attribute [elab_as_eliminator] protected theorem induction_on₂ {C : trunc α → trunc β → Prop} (q₁ : trunc α) (q₂ : trunc β) (h : ∀ a b, C (mk a) (mk b)) : C q₁ q₂ := trunc.induction_on q₁ $ λ a₁, trunc.induction_on q₂ (h a₁) protected theorem eq (a b : trunc α) : a = b := trunc.induction_on₂ a b (λ x y, quot.sound trivial) instance : subsingleton (trunc α) := ⟨trunc.eq⟩ def bind (q : trunc α) (f : α → trunc β) : trunc β := trunc.lift_on q f (λ a b, trunc.eq _ _) def map (f : α → β) (q : trunc α) : trunc β := bind q (trunc.mk ∘ f) instance : monad trunc := { pure := @trunc.mk, bind := @trunc.bind } instance : is_lawful_monad trunc := { id_map := λ α q, trunc.eq _ _, pure_bind := λ α β q f, rfl, bind_assoc := λ α β γ x f g, trunc.eq _ _ } variable {C : trunc α → Sort*} @[reducible, elab_as_eliminator] protected def rec (f : Π a, C (mk a)) (h : ∀ (a b : α), (eq.rec (f a) (trunc.eq (mk a) (mk b)) : C (mk b)) = f b) (q : trunc α) : C q := quot.rec f (λ a b _, h a b) q @[reducible, elab_as_eliminator] protected def rec_on (q : trunc α) (f : Π a, C (mk a)) (h : ∀ (a b : α), (eq.rec (f a) (trunc.eq (mk a) (mk b)) : C (mk b)) = f b) : C q := trunc.rec f h q @[reducible, elab_as_eliminator] protected def rec_on_subsingleton [∀ a, subsingleton (C (mk a))] (q : trunc α) (f : Π a, C (mk a)) : C q := trunc.rec f (λ a b, subsingleton.elim _ (f b)) q /-- Noncomputably extract a representative of `trunc α` (using the axiom of choice). -/ noncomputable def out : trunc α → α := quot.out @[simp] theorem out_eq (q : trunc α) : mk q.out = q := trunc.eq _ _ end trunc theorem nonempty_of_trunc (q : trunc α) : nonempty α := let ⟨a, _⟩ := q.exists_rep in ⟨a⟩ namespace quotient variables {γ : Sort*} {φ : Sort*} {s₁ : setoid α} {s₂ : setoid β} {s₃ : setoid γ} /- Versions of quotient definitions and lemmas ending in `'` use unification instead of typeclass inference for inferring the `setoid` argument. This is useful when there are several different quotient relations on a type, for example quotient groups, rings and modules -/ protected def mk' (a : α) : quotient s₁ := quot.mk s₁.1 a @[elab_as_eliminator, reducible] protected def lift_on' (q : quotient s₁) (f : α → φ) (h : ∀ a b, @setoid.r α s₁ a b → f a = f b) : φ := quotient.lift_on q f h @[elab_as_eliminator, reducible] protected def lift_on₂' (q₁ : quotient s₁) (q₂ : quotient s₂) (f : α → β → γ) (h : ∀ a₁ a₂ b₁ b₂, @setoid.r α s₁ a₁ b₁ → @setoid.r β s₂ a₂ b₂ → f a₁ a₂ = f b₁ b₂) : γ := quotient.lift_on₂ q₁ q₂ f h @[elab_as_eliminator] protected lemma ind' {p : quotient s₁ → Prop} (h : ∀ a, p (quotient.mk' a)) (q : quotient s₁) : p q := quotient.ind h q @[elab_as_eliminator] protected lemma ind₂' {p : quotient s₁ → quotient s₂ → Prop} (h : ∀ a₁ a₂, p (quotient.mk' a₁) (quotient.mk' a₂)) (q₁ : quotient s₁) (q₂ : quotient s₂) : p q₁ q₂ := quotient.ind₂ h q₁ q₂ @[elab_as_eliminator] protected lemma induction_on' {p : quotient s₁ → Prop} (q : quotient s₁) (h : ∀ a, p (quotient.mk' a)) : p q := quotient.induction_on q h @[elab_as_eliminator] protected lemma induction_on₂' {p : quotient s₁ → quotient s₂ → Prop} (q₁ : quotient s₁) (q₂ : quotient s₂) (h : ∀ a₁ a₂, p (quotient.mk' a₁) (quotient.mk' a₂)) : p q₁ q₂ := quotient.induction_on₂ q₁ q₂ h @[elab_as_eliminator] protected lemma induction_on₃' {p : quotient s₁ → quotient s₂ → quotient s₃ → Prop} (q₁ : quotient s₁) (q₂ : quotient s₂) (q₃ : quotient s₃) (h : ∀ a₁ a₂ a₃, p (quotient.mk' a₁) (quotient.mk' a₂) (quotient.mk' a₃)) : p q₁ q₂ q₃ := quotient.induction_on₃ q₁ q₂ q₃ h lemma exact' {a b : α} : (quotient.mk' a : quotient s₁) = quotient.mk' b → @setoid.r _ s₁ a b := quotient.exact lemma sound' {a b : α} : @setoid.r _ s₁ a b → @quotient.mk' α s₁ a = quotient.mk' b := quotient.sound @[simp] protected lemma eq' {a b : α} : @quotient.mk' α s₁ a = quotient.mk' b ↔ @setoid.r _ s₁ a b := quotient.eq noncomputable def out' (a : quotient s₁) : α := quotient.out a @[simp] theorem out_eq' (q : quotient s₁) : quotient.mk' q.out' = q := q.out_eq theorem mk_out' (a : α) : @setoid.r α s₁ (quotient.mk' a : quotient s₁).out' a := quotient.exact (quotient.out_eq _) end quotient
113c2fcf70b135e92ebe1976836740142d051a80
e151e9053bfd6d71740066474fc500a087837323
/src/hott/cubical/squareover.lean
6b3d71be6e42ddfc79dd3533387627007e0d6146
[ "Apache-2.0" ]
permissive
daniel-carranza/hott3
15bac2d90589dbb952ef15e74b2837722491963d
913811e8a1371d3a5751d7d32ff9dec8aa6815d9
refs/heads/master
1,610,091,349,670
1,596,222,336,000
1,596,222,336,000
241,957,822
0
0
Apache-2.0
1,582,222,839,000
1,582,222,838,000
null
UTF-8
Lean
false
false
16,698
lean
/- Copyright (c) 2015 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Floris van Doorn Squareovers -/ import .square universe u hott_theory namespace hott open eq hott.equiv hott.is_equiv hott.sigma namespace eq -- we give the argument B explicitly, because Lean would find (λa, B a) by itself, which -- makes the type uglier (of course the two terms are definitionally equal) inductive squareover {A : Type _} (B : A → Type _) {a₀₀ : A} {b₀₀ : B a₀₀} : Π{a₂₀ a₀₂ a₂₂ : A} {p₁₀ : a₀₀ = a₂₀} {p₁₂ : a₀₂ = a₂₂} {p₀₁ : a₀₀ = a₀₂} {p₂₁ : a₂₀ = a₂₂} (s₁₁ : square p₁₀ p₁₂ p₀₁ p₂₁) {b₂₀ : B a₂₀} {b₀₂ : B a₀₂} {b₂₂ : B a₂₂} (q₁₀ : b₀₀ =[p₁₀; B] b₂₀) (q₁₂ : b₀₂ =[p₁₂; B] b₂₂) (q₀₁ : b₀₀ =[p₀₁; B] b₀₂) (q₂₁ : b₂₀ =[p₂₁; B] b₂₂), Type _ | idsquareo : squareover ids idpo idpo idpo idpo variables {A : Type _} {A' : Type _} {B : A → Type _} {a a' a'' a₀₀ a₂₀ a₄₀ a₀₂ a₂₂ a₂₄ a₀₄ a₄₂ a₄₄ : A} /-a₀₀-/ {p₁₀ : a₀₀ = a₂₀} /-a₂₀-/ {p₃₀ : a₂₀ = a₄₀} /-a₄₀-/ {p₀₁ : a₀₀ = a₀₂} /-s₁₁-/ {p₂₁ : a₂₀ = a₂₂} /-s₃₁-/ {p₄₁ : a₄₀ = a₄₂} /-a₀₂-/ {p₁₂ : a₀₂ = a₂₂} /-a₂₂-/ {p₃₂ : a₂₂ = a₄₂} /-a₄₂-/ {p₀₃ : a₀₂ = a₀₄} /-s₁₃-/ {p₂₃ : a₂₂ = a₂₄} /-s₃₃-/ {p₄₃ : a₄₂ = a₄₄} /-a₀₄-/ {p₁₄ : a₀₄ = a₂₄} /-a₂₄-/ {p₃₄ : a₂₄ = a₄₄} /-a₄₄-/ {s₁₁ : square p₁₀ p₁₂ p₀₁ p₂₁} {s₃₁ : square p₃₀ p₃₂ p₂₁ p₄₁} {s₁₃ : square p₁₂ p₁₄ p₀₃ p₂₃} {s₃₃ : square p₃₂ p₃₄ p₂₃ p₄₃} {b₀₀ : B a₀₀} {b₂₀ : B a₂₀} {b₄₀ : B a₄₀} {b₀₂ : B a₀₂} {b₂₂ : B a₂₂} {b₄₂ : B a₄₂} {b₀₄ : B a₀₄} {b₂₄ : B a₂₄} {b₄₄ : B a₄₄} /-b₀₀-/ {q₁₀ : b₀₀ =[p₁₀] b₂₀} /-b₂₀-/ {q₃₀ : b₂₀ =[p₃₀] b₄₀} /-b₄₀-/ {q₀₁ : b₀₀ =[p₀₁] b₀₂} /-t₁₁-/ {q₂₁ : b₂₀ =[p₂₁] b₂₂} /-t₃₁-/ {q₄₁ : b₄₀ =[p₄₁] b₄₂} /-b₀₂-/ {q₁₂ : b₀₂ =[p₁₂] b₂₂} /-b₂₂-/ {q₃₂ : b₂₂ =[p₃₂] b₄₂} /-b₄₂-/ {q₀₃ : b₀₂ =[p₀₃] b₀₄} /-t₁₃-/ {q₂₃ : b₂₂ =[p₂₃] b₂₄} /-t₃₃-/ {q₄₃ : b₄₂ =[p₄₃] b₄₄} /-b₀₄-/ {q₁₄ : b₀₄ =[p₁₄] b₂₄} /-b₂₄-/ {q₃₄ : b₂₄ =[p₃₄] b₄₄} /-b₄₄-/ @[hott] def squareo := @squareover A B a₀₀ @[hott, reducible] def idsquareo (b₀₀ : B a₀₀) := @squareover.idsquareo A B a₀₀ b₀₀ @[hott, reducible] def idso := @squareover.idsquareo A B a₀₀ b₀₀ @[hott] def apds (f : Πa, B a) (s : square p₁₀ p₁₂ p₀₁ p₂₁) : squareover B s (apd f p₁₀) (apd f p₁₂) (apd f p₀₁) (apd f p₂₁) := by induction s; constructor @[hott] def vrflo : squareover B vrfl q₁₀ q₁₀ idpo idpo := by induction q₁₀; exact idso @[hott] def hrflo : squareover B hrfl idpo idpo q₁₀ q₁₀ := by induction q₁₀; exact idso @[hott] def vdeg_squareover {p₁₀'} {s : p₁₀ = p₁₀'} {q₁₀' : b₀₀ =[p₁₀'] b₂₀} (r : change_path s q₁₀ = q₁₀') : squareover B (vdeg_square s) q₁₀ q₁₀' idpo idpo := by induction s; induction r; exact vrflo @[hott] def hdeg_squareover {p₀₁'} {s : p₀₁ = p₀₁'} {q₀₁' : b₀₀ =[p₀₁'] b₀₂} (r : change_path s q₀₁ = q₀₁') : squareover B (hdeg_square s) idpo idpo q₀₁ q₀₁' := by induction s; induction r; exact hrflo @[hott] def hconcato (t₁₁ : squareover B s₁₁ q₁₀ q₁₂ q₀₁ q₂₁) (t₃₁ : squareover B s₃₁ q₃₀ q₃₂ q₂₁ q₄₁) : squareover B (hconcat s₁₁ s₃₁) (q₁₀ ⬝o q₃₀) (q₁₂ ⬝o q₃₂) q₀₁ q₄₁ := by induction t₃₁; exact t₁₁ @[hott] def vconcato (t₁₁ : squareover B s₁₁ q₁₀ q₁₂ q₀₁ q₂₁) (t₁₃ : squareover B s₁₃ q₁₂ q₁₄ q₀₃ q₂₃) : squareover B (vconcat s₁₁ s₁₃) q₁₀ q₁₄ (q₀₁ ⬝o q₀₃) (q₂₁ ⬝o q₂₃) := by induction t₁₃; exact t₁₁ @[hott] def hinverseo (t₁₁ : squareover B s₁₁ q₁₀ q₁₂ q₀₁ q₂₁) : squareover B (hinverse s₁₁) q₁₀⁻¹ᵒ q₁₂⁻¹ᵒ q₂₁ q₀₁ := by induction t₁₁; constructor @[hott] def vinverseo (t₁₁ : squareover B s₁₁ q₁₀ q₁₂ q₀₁ q₂₁) : squareover B (vinverse s₁₁) q₁₂ q₁₀ q₀₁⁻¹ᵒ q₂₁⁻¹ᵒ := by induction t₁₁; constructor @[hott] def eq_vconcato {q : b₀₀ =[p₁₀] b₂₀} (r : q = q₁₀) (t₁₁ : squareover B s₁₁ q₁₀ q₁₂ q₀₁ q₂₁) : squareover B s₁₁ q q₁₂ q₀₁ q₂₁ := by induction r; exact t₁₁ @[hott] def vconcato_eq {q : b₀₂ =[p₁₂] b₂₂} (t₁₁ : squareover B s₁₁ q₁₀ q₁₂ q₀₁ q₂₁) (r : q₁₂ = q) : squareover B s₁₁ q₁₀ q q₀₁ q₂₁ := by induction r; exact t₁₁ @[hott] def eq_hconcato {q : b₀₀ =[p₀₁] b₀₂} (r : q = q₀₁) (t₁₁ : squareover B s₁₁ q₁₀ q₁₂ q₀₁ q₂₁) : squareover B s₁₁ q₁₀ q₁₂ q q₂₁ := by induction r; exact t₁₁ @[hott] def hconcato_eq {q : b₂₀ =[p₂₁] b₂₂} (t₁₁ : squareover B s₁₁ q₁₀ q₁₂ q₀₁ q₂₁) (r : q₂₁ = q) : squareover B s₁₁ q₁₀ q₁₂ q₀₁ q := by induction r; exact t₁₁ @[hott] def pathover_vconcato {p : a₀₀ = a₂₀} {sp : p = p₁₀} {q : b₀₀ =[p] b₂₀} (r : change_path sp q = q₁₀) (t₁₁ : squareover B s₁₁ q₁₀ q₁₂ q₀₁ q₂₁) : squareover B (sp ⬝pv s₁₁) q q₁₂ q₀₁ q₂₁ := by induction sp; induction r; exact t₁₁ @[hott] def vconcato_pathover {p : a₀₂ = a₂₂} {sp : p₁₂ = p} {q : b₀₂ =[p] b₂₂} (t₁₁ : squareover B s₁₁ q₁₀ q₁₂ q₀₁ q₂₁) (r : change_path sp q₁₂ = q) : squareover B (s₁₁ ⬝vp sp) q₁₀ q q₀₁ q₂₁ := by induction sp; induction r; exact t₁₁ @[hott] def pathover_hconcato {p : a₀₀ = a₀₂} {sp : p = p₀₁} {q : b₀₀ =[p] b₀₂} (r : change_path sp q = q₀₁) (t₁₁ : squareover B s₁₁ q₁₀ q₁₂ q₀₁ q₂₁) : squareover B (sp ⬝ph s₁₁) q₁₀ q₁₂ q q₂₁ := by induction sp; induction r; exact t₁₁ @[hott] def hconcato_pathover {p : a₂₀ = a₂₂} {sp : p₂₁ = p} {q : b₂₀ =[p] b₂₂} (t₁₁ : squareover B s₁₁ q₁₀ q₁₂ q₀₁ q₂₁) (r : change_path sp q₂₁ = q) : squareover B (s₁₁ ⬝hp sp) q₁₀ q₁₂ q₀₁ q := by induction sp; induction r; exact t₁₁ infix ` ⬝ho `:69 := hconcato --type using \tr infix ` ⬝vo `:70 := vconcato --type using \tr infix ` ⬝hop `:72 := hconcato_eq --type using \tr infix ` ⬝vop `:74 := vconcato_eq --type using \tr infix ` ⬝pho `:71 := eq_hconcato --type using \tr infix ` ⬝pvo `:73 := eq_vconcato --type using \tr @[hott] def square_of_squareover (t₁₁ : squareover B s₁₁ q₁₀ q₁₂ q₀₁ q₂₁) : square (con_tr p₁₀ p₂₁ b₀₀ ⬝ ap (λa : B a₂₀, p₂₁ ▸ a) (tr_eq_of_pathover q₁₀)) (tr_eq_of_pathover q₁₂) (transport2 _ (eq_of_square s₁₁) b₀₀ ⬝ con_tr _ _ _ ⬝ ap (λa : B a₀₂, p₁₂ ▸ a) (tr_eq_of_pathover q₀₁)) (tr_eq_of_pathover q₂₁) := by induction t₁₁; constructor variable (B) @[hott] def square_of_squareover_ids {b₀₀ b₀₂ b₂₀ b₂₂ : B a} {t : b₀₀ = b₂₀} {b : b₀₂ = b₂₂} {l : b₀₀ = b₀₂} {r : b₂₀ = b₂₂} (so : squareover B ids (pathover_idp_of_eq B t) (pathover_idp_of_eq B b) (pathover_idp_of_eq B l) (pathover_idp_of_eq B r)) : square t b l r := begin let H := square_of_squareover so, hsimp at H, exact whisker_square (to_right_inv (pathover_equiv_tr_eq (refl a) _ _) _) (to_right_inv (pathover_equiv_tr_eq (refl a) _ _) _) (to_right_inv (pathover_equiv_tr_eq (refl a) _ _) _) (to_right_inv (pathover_equiv_tr_eq (refl a) _ _) _) H end @[hott] def squareover_ids_of_square {b₀₀ b₀₂ b₂₀ b₂₂ : B a} {t : b₀₀ = b₂₀} {b : b₀₂ = b₂₂} {l : b₀₀ = b₀₂} {r : b₂₀ = b₂₂} (q : square t b l r) : squareover B ids (pathover_idp_of_eq B t) (pathover_idp_of_eq B b) (pathover_idp_of_eq B l) (pathover_idp_of_eq B r) := by induction q; constructor -- relating pathovers to squareovers variable {B} @[hott] def pathover_of_squareover' (t₁₁ : squareover B s₁₁ q₁₀ q₁₂ q₀₁ q₂₁) : q₁₀ ⬝o q₂₁ =[eq_of_square s₁₁; λp, b₀₀ =[p] b₂₂] q₀₁ ⬝o q₁₂ := by induction t₁₁; constructor @[hott] def pathover_of_squareover {s : p₁₀ ⬝ p₂₁ = p₀₁ ⬝ p₁₂} (t₁₁ : squareover B (square_of_eq s) q₁₀ q₁₂ q₀₁ q₂₁) : q₁₀ ⬝o q₂₁ =[s; λp, b₀₀ =[p] b₂₂] q₀₁ ⬝o q₁₂ := begin revert s t₁₁, refine equiv_rect' (square_equiv_eq p₁₀ p₁₂ p₀₁ p₂₁)⁻¹ᵉ (λa b, squareover B b q₁₀ q₁₂ q₀₁ q₂₁ → q₁₀ ⬝o q₂₁ =[a; λp, b₀₀ =[p] b₂₂] q₀₁ ⬝o q₁₂) _, intro s, exact pathover_of_squareover' end @[hott] def squareover_of_pathover {s : p₁₀ ⬝ p₂₁ = p₀₁ ⬝ p₁₂} (r : q₁₀ ⬝o q₂₁ =[s; λp, b₀₀ =[p] b₂₂] q₀₁ ⬝o q₁₂) : squareover B (square_of_eq s) q₁₀ q₁₂ q₀₁ q₂₁ := by induction q₁₂; hsimp at r; induction r; induction q₁₀; induction q₂₁; constructor @[hott] def pathover_top_of_squareover (t₁₁ : squareover B s₁₁ q₁₀ q₁₂ q₀₁ q₂₁) : q₁₀ =[eq_top_of_square s₁₁; λp, b₀₀ =[p] b₂₀] q₀₁ ⬝o q₁₂ ⬝o q₂₁⁻¹ᵒ := by induction t₁₁; constructor @[hott] def squareover_of_pathover_top {s : p₁₀ = p₀₁ ⬝ p₁₂ ⬝ p₂₁⁻¹} (r : q₁₀ =[s; λp, b₀₀ =[p] b₂₀] q₀₁ ⬝o q₁₂ ⬝o q₂₁⁻¹ᵒ) : squareover B (square_of_eq_top s) q₁₀ q₁₂ q₀₁ q₂₁ := by induction q₂₁; induction q₁₂; dsimp at r; induction r; induction q₁₀; constructor @[hott] def pathover_of_hdeg_squareover {p₀₁' : a₀₀ = a₀₂} {r : p₀₁ = p₀₁'} {q₀₁' : b₀₀ =[p₀₁'] b₀₂} (t : squareover B (hdeg_square r) idpo idpo q₀₁ q₀₁') : q₀₁ =[r; λp, b₀₀ =[p] b₀₂] q₀₁' := by induction r; induction q₀₁'; exact (pathover_of_squareover' t)⁻¹ᵒ @[hott] def pathover_of_vdeg_squareover {p₁₀' : a₀₀ = a₂₀} {r : p₁₀ = p₁₀'} {q₁₀' : b₀₀ =[p₁₀'] b₂₀} (t : squareover B (vdeg_square r) q₁₀ q₁₀' idpo idpo) : q₁₀ =[r; λp, b₀₀ =[p] b₂₀] q₁₀' := by induction r; induction q₁₀'; exact pathover_of_squareover' t @[hott] def squareover_of_eq_top (r : change_path (eq_top_of_square s₁₁) q₁₀ = q₀₁ ⬝o q₁₂ ⬝o q₂₁⁻¹ᵒ) : squareover B s₁₁ q₁₀ q₁₂ q₀₁ q₂₁ := begin induction s₁₁, revert q₁₂ q₁₀ r, refine idp_rec_on q₂₁ _, clear q₂₁, intro q₁₂, refine idp_rec_on q₁₂ _, clear q₁₂, dsimp, intros, induction r, eapply idp_rec_on q₁₀, constructor end @[hott] def eq_top_of_squareover (r : squareover B s₁₁ q₁₀ q₁₂ q₀₁ q₂₁) : change_path (eq_top_of_square s₁₁) q₁₀ = q₀₁ ⬝o q₁₂ ⬝o q₂₁⁻¹ᵒ := by induction r; reflexivity @[hott] def change_square {s₁₁'} (p : s₁₁ = s₁₁') (r : squareover B s₁₁ q₁₀ q₁₂ q₀₁ q₂₁) : squareover B s₁₁' q₁₀ q₁₂ q₀₁ q₂₁ := by induction p; exact r -- in Lean 2 defined using transport @[hott] lemma eq_of_vdeg_squareover {q₁₀' : b₀₀ =[p₁₀] b₂₀} (p : squareover B vrfl q₁₀ q₁₀' idpo idpo) : q₁₀ = q₁₀' := begin let H := square_of_squareover p, induction p₁₀, hsimp at H, let H' := eq_of_vdeg_square H, exact eq_of_fn_eq_fn (pathover_equiv_tr_eq _ _ _) H' end /- A version of eq_pathover where the type of the equality also varies -/ @[hott] lemma eq_pathover_dep {f g : Πa, B a} {p : a = a'} {q : f a = g a} {r : f a' = g a'} (s : squareover B hrfl (pathover_idp_of_eq B q) (pathover_idp_of_eq B r) (apd f p) (apd g p)) : q =[p; λx, f x = g x] r := begin induction p, apply pathover_idp_of_eq, apply eq_of_vdeg_square, exact square_of_squareover_ids _ s end /- charcaterization of pathovers in pathovers -/ -- in this version the fibration (B) of the pathover does not depend on the variable (a) @[hott] lemma pathover_pathover {a' a₂' : A'} {p : a' = a₂'} {f g : A' → A} {b : Πa, B (f a)} {b₂ : Πa, B (g a)} {q : Π(a' : A'), f a' = g a'} (r : b a' =[q a'; B] b₂ a') (r₂ : b a₂' =[q a₂'; B] b₂ a₂') (s : squareover B (natural_square q p) r r₂ (pathover_ap B f (apd b p)) (pathover_ap B g (apd b₂ p))) : r =[p; λa, b a =[q a; B] b₂ a] r₂ := begin induction p, apply pathover_idp_of_eq, apply eq_of_vdeg_squareover, exact s end @[hott] def squareover_change_path_left {p₀₁' : a₀₀ = a₀₂} (r : p₀₁' = p₀₁) {q₀₁ : b₀₀ =[p₀₁'] b₀₂} (t : squareover B (r ⬝ph s₁₁) q₁₀ q₁₂ q₀₁ q₂₁) : squareover B s₁₁ q₁₀ q₁₂ (change_path r q₀₁) q₂₁ := by induction r; exact t @[hott] def squareover_change_path_right {p₂₁' : a₂₀ = a₂₂} (r : p₂₁' = p₂₁) {q₂₁ : b₂₀ =[p₂₁'] b₂₂} (t : squareover B (s₁₁ ⬝hp r⁻¹) q₁₀ q₁₂ q₀₁ q₂₁) : squareover B s₁₁ q₁₀ q₁₂ q₀₁ (change_path r q₂₁) := by induction r; exact t @[hott] def squareover_change_path_right' {p₂₁' : a₂₀ = a₂₂} (r : p₂₁ = p₂₁') {q₂₁ : b₂₀ =[p₂₁'] b₂₂} (t : squareover B (s₁₁ ⬝hp r) q₁₀ q₁₂ q₀₁ q₂₁) : squareover B s₁₁ q₁₀ q₁₂ q₀₁ (change_path r⁻¹ q₂₁) := by induction r; exact t /- You can construct a square in a sigma-type by giving a squareover -/ @[hott] def square_dpair_eq_dpair {a₀₀ a₂₀ a₀₂ a₂₂ : A} {p₁₀ : a₀₀ = a₂₀} {p₀₁ : a₀₀ = a₀₂} {p₂₁ : a₂₀ = a₂₂} {p₁₂ : a₀₂ = a₂₂} (s₁₁ : square p₁₀ p₁₂ p₀₁ p₂₁) {b₀₀ : B a₀₀} {b₂₀ : B a₂₀} {b₀₂ : B a₀₂} {b₂₂ : B a₂₂} {q₁₀ : b₀₀ =[p₁₀] b₂₀} {q₀₁ : b₀₀ =[p₀₁] b₀₂} {q₂₁ : b₂₀ =[p₂₁] b₂₂} {q₁₂ : b₀₂ =[p₁₂] b₂₂} (t₁₁ : squareover B s₁₁ q₁₀ q₁₂ q₀₁ q₂₁) : square (sigma.dpair_eq_dpair p₁₀ q₁₀) (dpair_eq_dpair p₁₂ q₁₂) (dpair_eq_dpair p₀₁ q₀₁) (dpair_eq_dpair p₂₁ q₂₁) := by induction t₁₁; constructor @[hott] lemma sigma_square {v₀₀ v₂₀ v₀₂ v₂₂ : Σa, B a} {p₁₀ : v₀₀ = v₂₀} {p₀₁ : v₀₀ = v₀₂} {p₂₁ : v₂₀ = v₂₂} {p₁₂ : v₀₂ = v₂₂} (s₁₁ : square p₁₀..1 p₁₂..1 p₀₁..1 p₂₁..1) (t₁₁ : squareover B s₁₁ p₁₀..2 p₁₂..2 p₀₁..2 p₂₁..2) : square p₁₀ p₁₂ p₀₁ p₂₁ := begin induction v₀₀, induction v₂₀, induction v₀₂, induction v₂₂, rwr [(sigma_eq_eta p₁₀)⁻¹, (sigma_eq_eta p₀₁)⁻¹, (sigma_eq_eta p₁₂)⁻¹, (sigma_eq_eta p₂₁)⁻¹], exact square_dpair_eq_dpair s₁₁ t₁₁ end end eq end hott
7cb9ea80190f3bdb94df8a7a7c8fe83f64b0ad17
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/simpperf/pre2000.lean
3beb233d4c555d5a4f59fbbcad33105f8a94b832
[ "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
173,530
lean
axiom f (x : Prop) : Prop axiom g0 (x : Prop) : Prop axiom g1 (x : Prop) : Prop axiom g2 (x : Prop) : Prop axiom g3 (x : Prop) : Prop axiom g4 (x : Prop) : Prop axiom g5 (x : Prop) : Prop axiom g6 (x : Prop) : Prop axiom g7 (x : Prop) : Prop axiom g8 (x : Prop) : Prop axiom g9 (x : Prop) : Prop axiom g10 (x : Prop) : Prop axiom g11 (x : Prop) : Prop axiom g12 (x : Prop) : Prop axiom g13 (x : Prop) : Prop axiom g14 (x : Prop) : Prop axiom g15 (x : Prop) : Prop axiom g16 (x : Prop) : Prop axiom g17 (x : Prop) : Prop axiom g18 (x : Prop) : Prop axiom g19 (x : Prop) : Prop axiom g20 (x : Prop) : Prop axiom g21 (x : Prop) : Prop axiom g22 (x : Prop) : Prop axiom g23 (x : Prop) : Prop axiom g24 (x : Prop) : Prop axiom g25 (x : Prop) : Prop axiom g26 (x : Prop) : Prop axiom g27 (x : Prop) : Prop axiom g28 (x : Prop) : Prop axiom g29 (x : Prop) : Prop axiom g30 (x : Prop) : Prop axiom g31 (x : Prop) : Prop axiom g32 (x : Prop) : Prop axiom g33 (x : Prop) : Prop axiom g34 (x : Prop) : Prop axiom g35 (x : Prop) : Prop axiom g36 (x : Prop) : Prop axiom g37 (x : Prop) : Prop axiom g38 (x : Prop) : Prop axiom g39 (x : Prop) : Prop axiom g40 (x : Prop) : Prop axiom g41 (x : Prop) : Prop axiom g42 (x : Prop) : Prop axiom g43 (x : Prop) : Prop axiom g44 (x : Prop) : Prop axiom g45 (x : Prop) : Prop axiom g46 (x : Prop) : Prop axiom g47 (x : Prop) : Prop axiom g48 (x : Prop) : Prop axiom g49 (x : Prop) : Prop axiom g50 (x : Prop) : Prop axiom g51 (x : Prop) : Prop axiom g52 (x : Prop) : Prop axiom g53 (x : Prop) : Prop axiom g54 (x : Prop) : Prop axiom g55 (x : Prop) : Prop axiom g56 (x : Prop) : Prop axiom g57 (x : Prop) : Prop axiom g58 (x : Prop) : Prop axiom g59 (x : Prop) : Prop axiom g60 (x : Prop) : Prop axiom g61 (x : Prop) : Prop axiom g62 (x : Prop) : Prop axiom g63 (x : Prop) : Prop axiom g64 (x : Prop) : Prop axiom g65 (x : Prop) : Prop axiom g66 (x : Prop) : Prop axiom g67 (x : Prop) : Prop axiom g68 (x : Prop) : Prop axiom g69 (x : Prop) : Prop axiom g70 (x : Prop) : Prop axiom g71 (x : Prop) : Prop axiom g72 (x : Prop) : Prop axiom g73 (x : Prop) : Prop axiom g74 (x : Prop) : Prop axiom g75 (x : Prop) : Prop axiom g76 (x : Prop) : Prop axiom g77 (x : Prop) : Prop axiom g78 (x : Prop) : Prop axiom g79 (x : Prop) : Prop axiom g80 (x : Prop) : Prop axiom g81 (x : Prop) : Prop axiom g82 (x : Prop) : Prop axiom g83 (x : Prop) : Prop axiom g84 (x : Prop) : Prop axiom g85 (x : Prop) : Prop axiom g86 (x : Prop) : Prop axiom g87 (x : Prop) : Prop axiom g88 (x : Prop) : Prop axiom g89 (x : Prop) : Prop axiom g90 (x : Prop) : Prop axiom g91 (x : Prop) : Prop axiom g92 (x : Prop) : Prop axiom g93 (x : Prop) : Prop axiom g94 (x : Prop) : Prop axiom g95 (x : Prop) : Prop axiom g96 (x : Prop) : Prop axiom g97 (x : Prop) : Prop axiom g98 (x : Prop) : Prop axiom g99 (x : Prop) : Prop axiom g100 (x : Prop) : Prop axiom g101 (x : Prop) : Prop axiom g102 (x : Prop) : Prop axiom g103 (x : Prop) : Prop axiom g104 (x : Prop) : Prop axiom g105 (x : Prop) : Prop axiom g106 (x : Prop) : Prop axiom g107 (x : Prop) : Prop axiom g108 (x : Prop) : Prop axiom g109 (x : Prop) : Prop axiom g110 (x : Prop) : Prop axiom g111 (x : Prop) : Prop axiom g112 (x : Prop) : Prop axiom g113 (x : Prop) : Prop axiom g114 (x : Prop) : Prop axiom g115 (x : Prop) : Prop axiom g116 (x : Prop) : Prop axiom g117 (x : Prop) : Prop axiom g118 (x : Prop) : Prop axiom g119 (x : Prop) : Prop axiom g120 (x : Prop) : Prop axiom g121 (x : Prop) : Prop axiom g122 (x : Prop) : Prop axiom g123 (x : Prop) : Prop axiom g124 (x : Prop) : Prop axiom g125 (x : Prop) : Prop axiom g126 (x : Prop) : Prop axiom g127 (x : Prop) : Prop axiom g128 (x : Prop) : Prop axiom g129 (x : Prop) : Prop axiom g130 (x : Prop) : Prop axiom g131 (x : Prop) : Prop axiom g132 (x : Prop) : Prop axiom g133 (x : Prop) : Prop axiom g134 (x : Prop) : Prop axiom g135 (x : Prop) : Prop axiom g136 (x : Prop) : Prop axiom g137 (x : Prop) : Prop axiom g138 (x : Prop) : Prop axiom g139 (x : Prop) : Prop axiom g140 (x : Prop) : Prop axiom g141 (x : Prop) : Prop axiom g142 (x : Prop) : Prop axiom g143 (x : Prop) : Prop axiom g144 (x : Prop) : Prop axiom g145 (x : Prop) : Prop axiom g146 (x : Prop) : Prop axiom g147 (x : Prop) : Prop axiom g148 (x : Prop) : Prop axiom g149 (x : Prop) : Prop axiom g150 (x : Prop) : Prop axiom g151 (x : Prop) : Prop axiom g152 (x : Prop) : Prop axiom g153 (x : Prop) : Prop axiom g154 (x : Prop) : Prop axiom g155 (x : Prop) : Prop axiom g156 (x : Prop) : Prop axiom g157 (x : Prop) : Prop axiom g158 (x : Prop) : Prop axiom g159 (x : Prop) : Prop axiom g160 (x : Prop) : Prop axiom g161 (x : Prop) : Prop axiom g162 (x : Prop) : Prop axiom g163 (x : Prop) : Prop axiom g164 (x : Prop) : Prop axiom g165 (x : Prop) : Prop axiom g166 (x : Prop) : Prop axiom g167 (x : Prop) : Prop axiom g168 (x : Prop) : Prop axiom g169 (x : Prop) : Prop axiom g170 (x : Prop) : Prop axiom g171 (x : Prop) : Prop axiom g172 (x : Prop) : Prop axiom g173 (x : Prop) : Prop axiom g174 (x : Prop) : Prop axiom g175 (x : Prop) : Prop axiom g176 (x : Prop) : Prop axiom g177 (x : Prop) : Prop axiom g178 (x : Prop) : Prop axiom g179 (x : Prop) : Prop axiom g180 (x : Prop) : Prop axiom g181 (x : Prop) : Prop axiom g182 (x : Prop) : Prop axiom g183 (x : Prop) : Prop axiom g184 (x : Prop) : Prop axiom g185 (x : Prop) : Prop axiom g186 (x : Prop) : Prop axiom g187 (x : Prop) : Prop axiom g188 (x : Prop) : Prop axiom g189 (x : Prop) : Prop axiom g190 (x : Prop) : Prop axiom g191 (x : Prop) : Prop axiom g192 (x : Prop) : Prop axiom g193 (x : Prop) : Prop axiom g194 (x : Prop) : Prop axiom g195 (x : Prop) : Prop axiom g196 (x : Prop) : Prop axiom g197 (x : Prop) : Prop axiom g198 (x : Prop) : Prop axiom g199 (x : Prop) : Prop axiom g200 (x : Prop) : Prop axiom g201 (x : Prop) : Prop axiom g202 (x : Prop) : Prop axiom g203 (x : Prop) : Prop axiom g204 (x : Prop) : Prop axiom g205 (x : Prop) : Prop axiom g206 (x : Prop) : Prop axiom g207 (x : Prop) : Prop axiom g208 (x : Prop) : Prop axiom g209 (x : Prop) : Prop axiom g210 (x : Prop) : Prop axiom g211 (x : Prop) : Prop axiom g212 (x : Prop) : Prop axiom g213 (x : Prop) : Prop axiom g214 (x : Prop) : Prop axiom g215 (x : Prop) : Prop axiom g216 (x : Prop) : Prop axiom g217 (x : Prop) : Prop axiom g218 (x : Prop) : Prop axiom g219 (x : Prop) : Prop axiom g220 (x : Prop) : Prop axiom g221 (x : Prop) : Prop axiom g222 (x : Prop) : Prop axiom g223 (x : Prop) : Prop axiom g224 (x : Prop) : Prop axiom g225 (x : Prop) : Prop axiom g226 (x : Prop) : Prop axiom g227 (x : Prop) : Prop axiom g228 (x : Prop) : Prop axiom g229 (x : Prop) : Prop axiom g230 (x : Prop) : Prop axiom g231 (x : Prop) : Prop axiom g232 (x : Prop) : Prop axiom g233 (x : Prop) : Prop axiom g234 (x : Prop) : Prop axiom g235 (x : Prop) : Prop axiom g236 (x : Prop) : Prop axiom g237 (x : Prop) : Prop axiom g238 (x : Prop) : Prop axiom g239 (x : Prop) : Prop axiom g240 (x : Prop) : Prop axiom g241 (x : Prop) : Prop axiom g242 (x : Prop) : Prop axiom g243 (x : Prop) : Prop axiom g244 (x : Prop) : Prop axiom g245 (x : Prop) : Prop axiom g246 (x : Prop) : Prop axiom g247 (x : Prop) : Prop axiom g248 (x : Prop) : Prop axiom g249 (x : Prop) : Prop axiom g250 (x : Prop) : Prop axiom g251 (x : Prop) : Prop axiom g252 (x : Prop) : Prop axiom g253 (x : Prop) : Prop axiom g254 (x : Prop) : Prop axiom g255 (x : Prop) : Prop axiom g256 (x : Prop) : Prop axiom g257 (x : Prop) : Prop axiom g258 (x : Prop) : Prop axiom g259 (x : Prop) : Prop axiom g260 (x : Prop) : Prop axiom g261 (x : Prop) : Prop axiom g262 (x : Prop) : Prop axiom g263 (x : Prop) : Prop axiom g264 (x : Prop) : Prop axiom g265 (x : Prop) : Prop axiom g266 (x : Prop) : Prop axiom g267 (x : Prop) : Prop axiom g268 (x : Prop) : Prop axiom g269 (x : Prop) : Prop axiom g270 (x : Prop) : Prop axiom g271 (x : Prop) : Prop axiom g272 (x : Prop) : Prop axiom g273 (x : Prop) : Prop axiom g274 (x : Prop) : Prop axiom g275 (x : Prop) : Prop axiom g276 (x : Prop) : Prop axiom g277 (x : Prop) : Prop axiom g278 (x : Prop) : Prop axiom g279 (x : Prop) : Prop axiom g280 (x : Prop) : Prop axiom g281 (x : Prop) : Prop axiom g282 (x : Prop) : Prop axiom g283 (x : Prop) : Prop axiom g284 (x : Prop) : Prop axiom g285 (x : Prop) : Prop axiom g286 (x : Prop) : Prop axiom g287 (x : Prop) : Prop axiom g288 (x : Prop) : Prop axiom g289 (x : Prop) : Prop axiom g290 (x : Prop) : Prop axiom g291 (x : Prop) : Prop axiom g292 (x : Prop) : Prop axiom g293 (x : Prop) : Prop axiom g294 (x : Prop) : Prop axiom g295 (x : Prop) : Prop axiom g296 (x : Prop) : Prop axiom g297 (x : Prop) : Prop axiom g298 (x : Prop) : Prop axiom g299 (x : Prop) : Prop axiom g300 (x : Prop) : Prop axiom g301 (x : Prop) : Prop axiom g302 (x : Prop) : Prop axiom g303 (x : Prop) : Prop axiom g304 (x : Prop) : Prop axiom g305 (x : Prop) : Prop axiom g306 (x : Prop) : Prop axiom g307 (x : Prop) : Prop axiom g308 (x : Prop) : Prop axiom g309 (x : Prop) : Prop axiom g310 (x : Prop) : Prop axiom g311 (x : Prop) : Prop axiom g312 (x : Prop) : Prop axiom g313 (x : Prop) : Prop axiom g314 (x : Prop) : Prop axiom g315 (x : Prop) : Prop axiom g316 (x : Prop) : Prop axiom g317 (x : Prop) : Prop axiom g318 (x : Prop) : Prop axiom g319 (x : Prop) : Prop axiom g320 (x : Prop) : Prop axiom g321 (x : Prop) : Prop axiom g322 (x : Prop) : Prop axiom g323 (x : Prop) : Prop axiom g324 (x : Prop) : Prop axiom g325 (x : Prop) : Prop axiom g326 (x : Prop) : Prop axiom g327 (x : Prop) : Prop axiom g328 (x : Prop) : Prop axiom g329 (x : Prop) : Prop axiom g330 (x : Prop) : Prop axiom g331 (x : Prop) : Prop axiom g332 (x : Prop) : Prop axiom g333 (x : Prop) : Prop axiom g334 (x : Prop) : Prop axiom g335 (x : Prop) : Prop axiom g336 (x : Prop) : Prop axiom g337 (x : Prop) : Prop axiom g338 (x : Prop) : Prop axiom g339 (x : Prop) : Prop axiom g340 (x : Prop) : Prop axiom g341 (x : Prop) : Prop axiom g342 (x : Prop) : Prop axiom g343 (x : Prop) : Prop axiom g344 (x : Prop) : Prop axiom g345 (x : Prop) : Prop axiom g346 (x : Prop) : Prop axiom g347 (x : Prop) : Prop axiom g348 (x : Prop) : Prop axiom g349 (x : Prop) : Prop axiom g350 (x : Prop) : Prop axiom g351 (x : Prop) : Prop axiom g352 (x : Prop) : Prop axiom g353 (x : Prop) : Prop axiom g354 (x : Prop) : Prop axiom g355 (x : Prop) : Prop axiom g356 (x : Prop) : Prop axiom g357 (x : Prop) : Prop axiom g358 (x : Prop) : Prop axiom g359 (x : Prop) : Prop axiom g360 (x : Prop) : Prop axiom g361 (x : Prop) : Prop axiom g362 (x : Prop) : Prop axiom g363 (x : Prop) : Prop axiom g364 (x : Prop) : Prop axiom g365 (x : Prop) : Prop axiom g366 (x : Prop) : Prop axiom g367 (x : Prop) : Prop axiom g368 (x : Prop) : Prop axiom g369 (x : Prop) : Prop axiom g370 (x : Prop) : Prop axiom g371 (x : Prop) : Prop axiom g372 (x : Prop) : Prop axiom g373 (x : Prop) : Prop axiom g374 (x : Prop) : Prop axiom g375 (x : Prop) : Prop axiom g376 (x : Prop) : Prop axiom g377 (x : Prop) : Prop axiom g378 (x : Prop) : Prop axiom g379 (x : Prop) : Prop axiom g380 (x : Prop) : Prop axiom g381 (x : Prop) : Prop axiom g382 (x : Prop) : Prop axiom g383 (x : Prop) : Prop axiom g384 (x : Prop) : Prop axiom g385 (x : Prop) : Prop axiom g386 (x : Prop) : Prop axiom g387 (x : Prop) : Prop axiom g388 (x : Prop) : Prop axiom g389 (x : Prop) : Prop axiom g390 (x : Prop) : Prop axiom g391 (x : Prop) : Prop axiom g392 (x : Prop) : Prop axiom g393 (x : Prop) : Prop axiom g394 (x : Prop) : Prop axiom g395 (x : Prop) : Prop axiom g396 (x : Prop) : Prop axiom g397 (x : Prop) : Prop axiom g398 (x : Prop) : Prop axiom g399 (x : Prop) : Prop axiom g400 (x : Prop) : Prop axiom g401 (x : Prop) : Prop axiom g402 (x : Prop) : Prop axiom g403 (x : Prop) : Prop axiom g404 (x : Prop) : Prop axiom g405 (x : Prop) : Prop axiom g406 (x : Prop) : Prop axiom g407 (x : Prop) : Prop axiom g408 (x : Prop) : Prop axiom g409 (x : Prop) : Prop axiom g410 (x : Prop) : Prop axiom g411 (x : Prop) : Prop axiom g412 (x : Prop) : Prop axiom g413 (x : Prop) : Prop axiom g414 (x : Prop) : Prop axiom g415 (x : Prop) : Prop axiom g416 (x : Prop) : Prop axiom g417 (x : Prop) : Prop axiom g418 (x : Prop) : Prop axiom g419 (x : Prop) : Prop axiom g420 (x : Prop) : Prop axiom g421 (x : Prop) : Prop axiom g422 (x : Prop) : Prop axiom g423 (x : Prop) : Prop axiom g424 (x : Prop) : Prop axiom g425 (x : Prop) : Prop axiom g426 (x : Prop) : Prop axiom g427 (x : Prop) : Prop axiom g428 (x : Prop) : Prop axiom g429 (x : Prop) : Prop axiom g430 (x : Prop) : Prop axiom g431 (x : Prop) : Prop axiom g432 (x : Prop) : Prop axiom g433 (x : Prop) : Prop axiom g434 (x : Prop) : Prop axiom g435 (x : Prop) : Prop axiom g436 (x : Prop) : Prop axiom g437 (x : Prop) : Prop axiom g438 (x : Prop) : Prop axiom g439 (x : Prop) : Prop axiom g440 (x : Prop) : Prop axiom g441 (x : Prop) : Prop axiom g442 (x : Prop) : Prop axiom g443 (x : Prop) : Prop axiom g444 (x : Prop) : Prop axiom g445 (x : Prop) : Prop axiom g446 (x : Prop) : Prop axiom g447 (x : Prop) : Prop axiom g448 (x : Prop) : Prop axiom g449 (x : Prop) : Prop axiom g450 (x : Prop) : Prop axiom g451 (x : Prop) : Prop axiom g452 (x : Prop) : Prop axiom g453 (x : Prop) : Prop axiom g454 (x : Prop) : Prop axiom g455 (x : Prop) : Prop axiom g456 (x : Prop) : Prop axiom g457 (x : Prop) : Prop axiom g458 (x : Prop) : Prop axiom g459 (x : Prop) : Prop axiom g460 (x : Prop) : Prop axiom g461 (x : Prop) : Prop axiom g462 (x : Prop) : Prop axiom g463 (x : Prop) : Prop axiom g464 (x : Prop) : Prop axiom g465 (x : Prop) : Prop axiom g466 (x : Prop) : Prop axiom g467 (x : Prop) : Prop axiom g468 (x : Prop) : Prop axiom g469 (x : Prop) : Prop axiom g470 (x : Prop) : Prop axiom g471 (x : Prop) : Prop axiom g472 (x : Prop) : Prop axiom g473 (x : Prop) : Prop axiom g474 (x : Prop) : Prop axiom g475 (x : Prop) : Prop axiom g476 (x : Prop) : Prop axiom g477 (x : Prop) : Prop axiom g478 (x : Prop) : Prop axiom g479 (x : Prop) : Prop axiom g480 (x : Prop) : Prop axiom g481 (x : Prop) : Prop axiom g482 (x : Prop) : Prop axiom g483 (x : Prop) : Prop axiom g484 (x : Prop) : Prop axiom g485 (x : Prop) : Prop axiom g486 (x : Prop) : Prop axiom g487 (x : Prop) : Prop axiom g488 (x : Prop) : Prop axiom g489 (x : Prop) : Prop axiom g490 (x : Prop) : Prop axiom g491 (x : Prop) : Prop axiom g492 (x : Prop) : Prop axiom g493 (x : Prop) : Prop axiom g494 (x : Prop) : Prop axiom g495 (x : Prop) : Prop axiom g496 (x : Prop) : Prop axiom g497 (x : Prop) : Prop axiom g498 (x : Prop) : Prop axiom g499 (x : Prop) : Prop axiom g500 (x : Prop) : Prop axiom g501 (x : Prop) : Prop axiom g502 (x : Prop) : Prop axiom g503 (x : Prop) : Prop axiom g504 (x : Prop) : Prop axiom g505 (x : Prop) : Prop axiom g506 (x : Prop) : Prop axiom g507 (x : Prop) : Prop axiom g508 (x : Prop) : Prop axiom g509 (x : Prop) : Prop axiom g510 (x : Prop) : Prop axiom g511 (x : Prop) : Prop axiom g512 (x : Prop) : Prop axiom g513 (x : Prop) : Prop axiom g514 (x : Prop) : Prop axiom g515 (x : Prop) : Prop axiom g516 (x : Prop) : Prop axiom g517 (x : Prop) : Prop axiom g518 (x : Prop) : Prop axiom g519 (x : Prop) : Prop axiom g520 (x : Prop) : Prop axiom g521 (x : Prop) : Prop axiom g522 (x : Prop) : Prop axiom g523 (x : Prop) : Prop axiom g524 (x : Prop) : Prop axiom g525 (x : Prop) : Prop axiom g526 (x : Prop) : Prop axiom g527 (x : Prop) : Prop axiom g528 (x : Prop) : Prop axiom g529 (x : Prop) : Prop axiom g530 (x : Prop) : Prop axiom g531 (x : Prop) : Prop axiom g532 (x : Prop) : Prop axiom g533 (x : Prop) : Prop axiom g534 (x : Prop) : Prop axiom g535 (x : Prop) : Prop axiom g536 (x : Prop) : Prop axiom g537 (x : Prop) : Prop axiom g538 (x : Prop) : Prop axiom g539 (x : Prop) : Prop axiom g540 (x : Prop) : Prop axiom g541 (x : Prop) : Prop axiom g542 (x : Prop) : Prop axiom g543 (x : Prop) : Prop axiom g544 (x : Prop) : Prop axiom g545 (x : Prop) : Prop axiom g546 (x : Prop) : Prop axiom g547 (x : Prop) : Prop axiom g548 (x : Prop) : Prop axiom g549 (x : Prop) : Prop axiom g550 (x : Prop) : Prop axiom g551 (x : Prop) : Prop axiom g552 (x : Prop) : Prop axiom g553 (x : Prop) : Prop axiom g554 (x : Prop) : Prop axiom g555 (x : Prop) : Prop axiom g556 (x : Prop) : Prop axiom g557 (x : Prop) : Prop axiom g558 (x : Prop) : Prop axiom g559 (x : Prop) : Prop axiom g560 (x : Prop) : Prop axiom g561 (x : Prop) : Prop axiom g562 (x : Prop) : Prop axiom g563 (x : Prop) : Prop axiom g564 (x : Prop) : Prop axiom g565 (x : Prop) : Prop axiom g566 (x : Prop) : Prop axiom g567 (x : Prop) : Prop axiom g568 (x : Prop) : Prop axiom g569 (x : Prop) : Prop axiom g570 (x : Prop) : Prop axiom g571 (x : Prop) : Prop axiom g572 (x : Prop) : Prop axiom g573 (x : Prop) : Prop axiom g574 (x : Prop) : Prop axiom g575 (x : Prop) : Prop axiom g576 (x : Prop) : Prop axiom g577 (x : Prop) : Prop axiom g578 (x : Prop) : Prop axiom g579 (x : Prop) : Prop axiom g580 (x : Prop) : Prop axiom g581 (x : Prop) : Prop axiom g582 (x : Prop) : Prop axiom g583 (x : Prop) : Prop axiom g584 (x : Prop) : Prop axiom g585 (x : Prop) : Prop axiom g586 (x : Prop) : Prop axiom g587 (x : Prop) : Prop axiom g588 (x : Prop) : Prop axiom g589 (x : Prop) : Prop axiom g590 (x : Prop) : Prop axiom g591 (x : Prop) : Prop axiom g592 (x : Prop) : Prop axiom g593 (x : Prop) : Prop axiom g594 (x : Prop) : Prop axiom g595 (x : Prop) : Prop axiom g596 (x : Prop) : Prop axiom g597 (x : Prop) : Prop axiom g598 (x : Prop) : Prop axiom g599 (x : Prop) : Prop axiom g600 (x : Prop) : Prop axiom g601 (x : Prop) : Prop axiom g602 (x : Prop) : Prop axiom g603 (x : Prop) : Prop axiom g604 (x : Prop) : Prop axiom g605 (x : Prop) : Prop axiom g606 (x : Prop) : Prop axiom g607 (x : Prop) : Prop axiom g608 (x : Prop) : Prop axiom g609 (x : Prop) : Prop axiom g610 (x : Prop) : Prop axiom g611 (x : Prop) : Prop axiom g612 (x : Prop) : Prop axiom g613 (x : Prop) : Prop axiom g614 (x : Prop) : Prop axiom g615 (x : Prop) : Prop axiom g616 (x : Prop) : Prop axiom g617 (x : Prop) : Prop axiom g618 (x : Prop) : Prop axiom g619 (x : Prop) : Prop axiom g620 (x : Prop) : Prop axiom g621 (x : Prop) : Prop axiom g622 (x : Prop) : Prop axiom g623 (x : Prop) : Prop axiom g624 (x : Prop) : Prop axiom g625 (x : Prop) : Prop axiom g626 (x : Prop) : Prop axiom g627 (x : Prop) : Prop axiom g628 (x : Prop) : Prop axiom g629 (x : Prop) : Prop axiom g630 (x : Prop) : Prop axiom g631 (x : Prop) : Prop axiom g632 (x : Prop) : Prop axiom g633 (x : Prop) : Prop axiom g634 (x : Prop) : Prop axiom g635 (x : Prop) : Prop axiom g636 (x : Prop) : Prop axiom g637 (x : Prop) : Prop axiom g638 (x : Prop) : Prop axiom g639 (x : Prop) : Prop axiom g640 (x : Prop) : Prop axiom g641 (x : Prop) : Prop axiom g642 (x : Prop) : Prop axiom g643 (x : Prop) : Prop axiom g644 (x : Prop) : Prop axiom g645 (x : Prop) : Prop axiom g646 (x : Prop) : Prop axiom g647 (x : Prop) : Prop axiom g648 (x : Prop) : Prop axiom g649 (x : Prop) : Prop axiom g650 (x : Prop) : Prop axiom g651 (x : Prop) : Prop axiom g652 (x : Prop) : Prop axiom g653 (x : Prop) : Prop axiom g654 (x : Prop) : Prop axiom g655 (x : Prop) : Prop axiom g656 (x : Prop) : Prop axiom g657 (x : Prop) : Prop axiom g658 (x : Prop) : Prop axiom g659 (x : Prop) : Prop axiom g660 (x : Prop) : Prop axiom g661 (x : Prop) : Prop axiom g662 (x : Prop) : Prop axiom g663 (x : Prop) : Prop axiom g664 (x : Prop) : Prop axiom g665 (x : Prop) : Prop axiom g666 (x : Prop) : Prop axiom g667 (x : Prop) : Prop axiom g668 (x : Prop) : Prop axiom g669 (x : Prop) : Prop axiom g670 (x : Prop) : Prop axiom g671 (x : Prop) : Prop axiom g672 (x : Prop) : Prop axiom g673 (x : Prop) : Prop axiom g674 (x : Prop) : Prop axiom g675 (x : Prop) : Prop axiom g676 (x : Prop) : Prop axiom g677 (x : Prop) : Prop axiom g678 (x : Prop) : Prop axiom g679 (x : Prop) : Prop axiom g680 (x : Prop) : Prop axiom g681 (x : Prop) : Prop axiom g682 (x : Prop) : Prop axiom g683 (x : Prop) : Prop axiom g684 (x : Prop) : Prop axiom g685 (x : Prop) : Prop axiom g686 (x : Prop) : Prop axiom g687 (x : Prop) : Prop axiom g688 (x : Prop) : Prop axiom g689 (x : Prop) : Prop axiom g690 (x : Prop) : Prop axiom g691 (x : Prop) : Prop axiom g692 (x : Prop) : Prop axiom g693 (x : Prop) : Prop axiom g694 (x : Prop) : Prop axiom g695 (x : Prop) : Prop axiom g696 (x : Prop) : Prop axiom g697 (x : Prop) : Prop axiom g698 (x : Prop) : Prop axiom g699 (x : Prop) : Prop axiom g700 (x : Prop) : Prop axiom g701 (x : Prop) : Prop axiom g702 (x : Prop) : Prop axiom g703 (x : Prop) : Prop axiom g704 (x : Prop) : Prop axiom g705 (x : Prop) : Prop axiom g706 (x : Prop) : Prop axiom g707 (x : Prop) : Prop axiom g708 (x : Prop) : Prop axiom g709 (x : Prop) : Prop axiom g710 (x : Prop) : Prop axiom g711 (x : Prop) : Prop axiom g712 (x : Prop) : Prop axiom g713 (x : Prop) : Prop axiom g714 (x : Prop) : Prop axiom g715 (x : Prop) : Prop axiom g716 (x : Prop) : Prop axiom g717 (x : Prop) : Prop axiom g718 (x : Prop) : Prop axiom g719 (x : Prop) : Prop axiom g720 (x : Prop) : Prop axiom g721 (x : Prop) : Prop axiom g722 (x : Prop) : Prop axiom g723 (x : Prop) : Prop axiom g724 (x : Prop) : Prop axiom g725 (x : Prop) : Prop axiom g726 (x : Prop) : Prop axiom g727 (x : Prop) : Prop axiom g728 (x : Prop) : Prop axiom g729 (x : Prop) : Prop axiom g730 (x : Prop) : Prop axiom g731 (x : Prop) : Prop axiom g732 (x : Prop) : Prop axiom g733 (x : Prop) : Prop axiom g734 (x : Prop) : Prop axiom g735 (x : Prop) : Prop axiom g736 (x : Prop) : Prop axiom g737 (x : Prop) : Prop axiom g738 (x : Prop) : Prop axiom g739 (x : Prop) : Prop axiom g740 (x : Prop) : Prop axiom g741 (x : Prop) : Prop axiom g742 (x : Prop) : Prop axiom g743 (x : Prop) : Prop axiom g744 (x : Prop) : Prop axiom g745 (x : Prop) : Prop axiom g746 (x : Prop) : Prop axiom g747 (x : Prop) : Prop axiom g748 (x : Prop) : Prop axiom g749 (x : Prop) : Prop axiom g750 (x : Prop) : Prop axiom g751 (x : Prop) : Prop axiom g752 (x : Prop) : Prop axiom g753 (x : Prop) : Prop axiom g754 (x : Prop) : Prop axiom g755 (x : Prop) : Prop axiom g756 (x : Prop) : Prop axiom g757 (x : Prop) : Prop axiom g758 (x : Prop) : Prop axiom g759 (x : Prop) : Prop axiom g760 (x : Prop) : Prop axiom g761 (x : Prop) : Prop axiom g762 (x : Prop) : Prop axiom g763 (x : Prop) : Prop axiom g764 (x : Prop) : Prop axiom g765 (x : Prop) : Prop axiom g766 (x : Prop) : Prop axiom g767 (x : Prop) : Prop axiom g768 (x : Prop) : Prop axiom g769 (x : Prop) : Prop axiom g770 (x : Prop) : Prop axiom g771 (x : Prop) : Prop axiom g772 (x : Prop) : Prop axiom g773 (x : Prop) : Prop axiom g774 (x : Prop) : Prop axiom g775 (x : Prop) : Prop axiom g776 (x : Prop) : Prop axiom g777 (x : Prop) : Prop axiom g778 (x : Prop) : Prop axiom g779 (x : Prop) : Prop axiom g780 (x : Prop) : Prop axiom g781 (x : Prop) : Prop axiom g782 (x : Prop) : Prop axiom g783 (x : Prop) : Prop axiom g784 (x : Prop) : Prop axiom g785 (x : Prop) : Prop axiom g786 (x : Prop) : Prop axiom g787 (x : Prop) : Prop axiom g788 (x : Prop) : Prop axiom g789 (x : Prop) : Prop axiom g790 (x : Prop) : Prop axiom g791 (x : Prop) : Prop axiom g792 (x : Prop) : Prop axiom g793 (x : Prop) : Prop axiom g794 (x : Prop) : Prop axiom g795 (x : Prop) : Prop axiom g796 (x : Prop) : Prop axiom g797 (x : Prop) : Prop axiom g798 (x : Prop) : Prop axiom g799 (x : Prop) : Prop axiom g800 (x : Prop) : Prop axiom g801 (x : Prop) : Prop axiom g802 (x : Prop) : Prop axiom g803 (x : Prop) : Prop axiom g804 (x : Prop) : Prop axiom g805 (x : Prop) : Prop axiom g806 (x : Prop) : Prop axiom g807 (x : Prop) : Prop axiom g808 (x : Prop) : Prop axiom g809 (x : Prop) : Prop axiom g810 (x : Prop) : Prop axiom g811 (x : Prop) : Prop axiom g812 (x : Prop) : Prop axiom g813 (x : Prop) : Prop axiom g814 (x : Prop) : Prop axiom g815 (x : Prop) : Prop axiom g816 (x : Prop) : Prop axiom g817 (x : Prop) : Prop axiom g818 (x : Prop) : Prop axiom g819 (x : Prop) : Prop axiom g820 (x : Prop) : Prop axiom g821 (x : Prop) : Prop axiom g822 (x : Prop) : Prop axiom g823 (x : Prop) : Prop axiom g824 (x : Prop) : Prop axiom g825 (x : Prop) : Prop axiom g826 (x : Prop) : Prop axiom g827 (x : Prop) : Prop axiom g828 (x : Prop) : Prop axiom g829 (x : Prop) : Prop axiom g830 (x : Prop) : Prop axiom g831 (x : Prop) : Prop axiom g832 (x : Prop) : Prop axiom g833 (x : Prop) : Prop axiom g834 (x : Prop) : Prop axiom g835 (x : Prop) : Prop axiom g836 (x : Prop) : Prop axiom g837 (x : Prop) : Prop axiom g838 (x : Prop) : Prop axiom g839 (x : Prop) : Prop axiom g840 (x : Prop) : Prop axiom g841 (x : Prop) : Prop axiom g842 (x : Prop) : Prop axiom g843 (x : Prop) : Prop axiom g844 (x : Prop) : Prop axiom g845 (x : Prop) : Prop axiom g846 (x : Prop) : Prop axiom g847 (x : Prop) : Prop axiom g848 (x : Prop) : Prop axiom g849 (x : Prop) : Prop axiom g850 (x : Prop) : Prop axiom g851 (x : Prop) : Prop axiom g852 (x : Prop) : Prop axiom g853 (x : Prop) : Prop axiom g854 (x : Prop) : Prop axiom g855 (x : Prop) : Prop axiom g856 (x : Prop) : Prop axiom g857 (x : Prop) : Prop axiom g858 (x : Prop) : Prop axiom g859 (x : Prop) : Prop axiom g860 (x : Prop) : Prop axiom g861 (x : Prop) : Prop axiom g862 (x : Prop) : Prop axiom g863 (x : Prop) : Prop axiom g864 (x : Prop) : Prop axiom g865 (x : Prop) : Prop axiom g866 (x : Prop) : Prop axiom g867 (x : Prop) : Prop axiom g868 (x : Prop) : Prop axiom g869 (x : Prop) : Prop axiom g870 (x : Prop) : Prop axiom g871 (x : Prop) : Prop axiom g872 (x : Prop) : Prop axiom g873 (x : Prop) : Prop axiom g874 (x : Prop) : Prop axiom g875 (x : Prop) : Prop axiom g876 (x : Prop) : Prop axiom g877 (x : Prop) : Prop axiom g878 (x : Prop) : Prop axiom g879 (x : Prop) : Prop axiom g880 (x : Prop) : Prop axiom g881 (x : Prop) : Prop axiom g882 (x : Prop) : Prop axiom g883 (x : Prop) : Prop axiom g884 (x : Prop) : Prop axiom g885 (x : Prop) : Prop axiom g886 (x : Prop) : Prop axiom g887 (x : Prop) : Prop axiom g888 (x : Prop) : Prop axiom g889 (x : Prop) : Prop axiom g890 (x : Prop) : Prop axiom g891 (x : Prop) : Prop axiom g892 (x : Prop) : Prop axiom g893 (x : Prop) : Prop axiom g894 (x : Prop) : Prop axiom g895 (x : Prop) : Prop axiom g896 (x : Prop) : Prop axiom g897 (x : Prop) : Prop axiom g898 (x : Prop) : Prop axiom g899 (x : Prop) : Prop axiom g900 (x : Prop) : Prop axiom g901 (x : Prop) : Prop axiom g902 (x : Prop) : Prop axiom g903 (x : Prop) : Prop axiom g904 (x : Prop) : Prop axiom g905 (x : Prop) : Prop axiom g906 (x : Prop) : Prop axiom g907 (x : Prop) : Prop axiom g908 (x : Prop) : Prop axiom g909 (x : Prop) : Prop axiom g910 (x : Prop) : Prop axiom g911 (x : Prop) : Prop axiom g912 (x : Prop) : Prop axiom g913 (x : Prop) : Prop axiom g914 (x : Prop) : Prop axiom g915 (x : Prop) : Prop axiom g916 (x : Prop) : Prop axiom g917 (x : Prop) : Prop axiom g918 (x : Prop) : Prop axiom g919 (x : Prop) : Prop axiom g920 (x : Prop) : Prop axiom g921 (x : Prop) : Prop axiom g922 (x : Prop) : Prop axiom g923 (x : Prop) : Prop axiom g924 (x : Prop) : Prop axiom g925 (x : Prop) : Prop axiom g926 (x : Prop) : Prop axiom g927 (x : Prop) : Prop axiom g928 (x : Prop) : Prop axiom g929 (x : Prop) : Prop axiom g930 (x : Prop) : Prop axiom g931 (x : Prop) : Prop axiom g932 (x : Prop) : Prop axiom g933 (x : Prop) : Prop axiom g934 (x : Prop) : Prop axiom g935 (x : Prop) : Prop axiom g936 (x : Prop) : Prop axiom g937 (x : Prop) : Prop axiom g938 (x : Prop) : Prop axiom g939 (x : Prop) : Prop axiom g940 (x : Prop) : Prop axiom g941 (x : Prop) : Prop axiom g942 (x : Prop) : Prop axiom g943 (x : Prop) : Prop axiom g944 (x : Prop) : Prop axiom g945 (x : Prop) : Prop axiom g946 (x : Prop) : Prop axiom g947 (x : Prop) : Prop axiom g948 (x : Prop) : Prop axiom g949 (x : Prop) : Prop axiom g950 (x : Prop) : Prop axiom g951 (x : Prop) : Prop axiom g952 (x : Prop) : Prop axiom g953 (x : Prop) : Prop axiom g954 (x : Prop) : Prop axiom g955 (x : Prop) : Prop axiom g956 (x : Prop) : Prop axiom g957 (x : Prop) : Prop axiom g958 (x : Prop) : Prop axiom g959 (x : Prop) : Prop axiom g960 (x : Prop) : Prop axiom g961 (x : Prop) : Prop axiom g962 (x : Prop) : Prop axiom g963 (x : Prop) : Prop axiom g964 (x : Prop) : Prop axiom g965 (x : Prop) : Prop axiom g966 (x : Prop) : Prop axiom g967 (x : Prop) : Prop axiom g968 (x : Prop) : Prop axiom g969 (x : Prop) : Prop axiom g970 (x : Prop) : Prop axiom g971 (x : Prop) : Prop axiom g972 (x : Prop) : Prop axiom g973 (x : Prop) : Prop axiom g974 (x : Prop) : Prop axiom g975 (x : Prop) : Prop axiom g976 (x : Prop) : Prop axiom g977 (x : Prop) : Prop axiom g978 (x : Prop) : Prop axiom g979 (x : Prop) : Prop axiom g980 (x : Prop) : Prop axiom g981 (x : Prop) : Prop axiom g982 (x : Prop) : Prop axiom g983 (x : Prop) : Prop axiom g984 (x : Prop) : Prop axiom g985 (x : Prop) : Prop axiom g986 (x : Prop) : Prop axiom g987 (x : Prop) : Prop axiom g988 (x : Prop) : Prop axiom g989 (x : Prop) : Prop axiom g990 (x : Prop) : Prop axiom g991 (x : Prop) : Prop axiom g992 (x : Prop) : Prop axiom g993 (x : Prop) : Prop axiom g994 (x : Prop) : Prop axiom g995 (x : Prop) : Prop axiom g996 (x : Prop) : Prop axiom g997 (x : Prop) : Prop axiom g998 (x : Prop) : Prop axiom g999 (x : Prop) : Prop axiom g1000 (x : Prop) : Prop axiom g1001 (x : Prop) : Prop axiom g1002 (x : Prop) : Prop axiom g1003 (x : Prop) : Prop axiom g1004 (x : Prop) : Prop axiom g1005 (x : Prop) : Prop axiom g1006 (x : Prop) : Prop axiom g1007 (x : Prop) : Prop axiom g1008 (x : Prop) : Prop axiom g1009 (x : Prop) : Prop axiom g1010 (x : Prop) : Prop axiom g1011 (x : Prop) : Prop axiom g1012 (x : Prop) : Prop axiom g1013 (x : Prop) : Prop axiom g1014 (x : Prop) : Prop axiom g1015 (x : Prop) : Prop axiom g1016 (x : Prop) : Prop axiom g1017 (x : Prop) : Prop axiom g1018 (x : Prop) : Prop axiom g1019 (x : Prop) : Prop axiom g1020 (x : Prop) : Prop axiom g1021 (x : Prop) : Prop axiom g1022 (x : Prop) : Prop axiom g1023 (x : Prop) : Prop axiom g1024 (x : Prop) : Prop axiom g1025 (x : Prop) : Prop axiom g1026 (x : Prop) : Prop axiom g1027 (x : Prop) : Prop axiom g1028 (x : Prop) : Prop axiom g1029 (x : Prop) : Prop axiom g1030 (x : Prop) : Prop axiom g1031 (x : Prop) : Prop axiom g1032 (x : Prop) : Prop axiom g1033 (x : Prop) : Prop axiom g1034 (x : Prop) : Prop axiom g1035 (x : Prop) : Prop axiom g1036 (x : Prop) : Prop axiom g1037 (x : Prop) : Prop axiom g1038 (x : Prop) : Prop axiom g1039 (x : Prop) : Prop axiom g1040 (x : Prop) : Prop axiom g1041 (x : Prop) : Prop axiom g1042 (x : Prop) : Prop axiom g1043 (x : Prop) : Prop axiom g1044 (x : Prop) : Prop axiom g1045 (x : Prop) : Prop axiom g1046 (x : Prop) : Prop axiom g1047 (x : Prop) : Prop axiom g1048 (x : Prop) : Prop axiom g1049 (x : Prop) : Prop axiom g1050 (x : Prop) : Prop axiom g1051 (x : Prop) : Prop axiom g1052 (x : Prop) : Prop axiom g1053 (x : Prop) : Prop axiom g1054 (x : Prop) : Prop axiom g1055 (x : Prop) : Prop axiom g1056 (x : Prop) : Prop axiom g1057 (x : Prop) : Prop axiom g1058 (x : Prop) : Prop axiom g1059 (x : Prop) : Prop axiom g1060 (x : Prop) : Prop axiom g1061 (x : Prop) : Prop axiom g1062 (x : Prop) : Prop axiom g1063 (x : Prop) : Prop axiom g1064 (x : Prop) : Prop axiom g1065 (x : Prop) : Prop axiom g1066 (x : Prop) : Prop axiom g1067 (x : Prop) : Prop axiom g1068 (x : Prop) : Prop axiom g1069 (x : Prop) : Prop axiom g1070 (x : Prop) : Prop axiom g1071 (x : Prop) : Prop axiom g1072 (x : Prop) : Prop axiom g1073 (x : Prop) : Prop axiom g1074 (x : Prop) : Prop axiom g1075 (x : Prop) : Prop axiom g1076 (x : Prop) : Prop axiom g1077 (x : Prop) : Prop axiom g1078 (x : Prop) : Prop axiom g1079 (x : Prop) : Prop axiom g1080 (x : Prop) : Prop axiom g1081 (x : Prop) : Prop axiom g1082 (x : Prop) : Prop axiom g1083 (x : Prop) : Prop axiom g1084 (x : Prop) : Prop axiom g1085 (x : Prop) : Prop axiom g1086 (x : Prop) : Prop axiom g1087 (x : Prop) : Prop axiom g1088 (x : Prop) : Prop axiom g1089 (x : Prop) : Prop axiom g1090 (x : Prop) : Prop axiom g1091 (x : Prop) : Prop axiom g1092 (x : Prop) : Prop axiom g1093 (x : Prop) : Prop axiom g1094 (x : Prop) : Prop axiom g1095 (x : Prop) : Prop axiom g1096 (x : Prop) : Prop axiom g1097 (x : Prop) : Prop axiom g1098 (x : Prop) : Prop axiom g1099 (x : Prop) : Prop axiom g1100 (x : Prop) : Prop axiom g1101 (x : Prop) : Prop axiom g1102 (x : Prop) : Prop axiom g1103 (x : Prop) : Prop axiom g1104 (x : Prop) : Prop axiom g1105 (x : Prop) : Prop axiom g1106 (x : Prop) : Prop axiom g1107 (x : Prop) : Prop axiom g1108 (x : Prop) : Prop axiom g1109 (x : Prop) : Prop axiom g1110 (x : Prop) : Prop axiom g1111 (x : Prop) : Prop axiom g1112 (x : Prop) : Prop axiom g1113 (x : Prop) : Prop axiom g1114 (x : Prop) : Prop axiom g1115 (x : Prop) : Prop axiom g1116 (x : Prop) : Prop axiom g1117 (x : Prop) : Prop axiom g1118 (x : Prop) : Prop axiom g1119 (x : Prop) : Prop axiom g1120 (x : Prop) : Prop axiom g1121 (x : Prop) : Prop axiom g1122 (x : Prop) : Prop axiom g1123 (x : Prop) : Prop axiom g1124 (x : Prop) : Prop axiom g1125 (x : Prop) : Prop axiom g1126 (x : Prop) : Prop axiom g1127 (x : Prop) : Prop axiom g1128 (x : Prop) : Prop axiom g1129 (x : Prop) : Prop axiom g1130 (x : Prop) : Prop axiom g1131 (x : Prop) : Prop axiom g1132 (x : Prop) : Prop axiom g1133 (x : Prop) : Prop axiom g1134 (x : Prop) : Prop axiom g1135 (x : Prop) : Prop axiom g1136 (x : Prop) : Prop axiom g1137 (x : Prop) : Prop axiom g1138 (x : Prop) : Prop axiom g1139 (x : Prop) : Prop axiom g1140 (x : Prop) : Prop axiom g1141 (x : Prop) : Prop axiom g1142 (x : Prop) : Prop axiom g1143 (x : Prop) : Prop axiom g1144 (x : Prop) : Prop axiom g1145 (x : Prop) : Prop axiom g1146 (x : Prop) : Prop axiom g1147 (x : Prop) : Prop axiom g1148 (x : Prop) : Prop axiom g1149 (x : Prop) : Prop axiom g1150 (x : Prop) : Prop axiom g1151 (x : Prop) : Prop axiom g1152 (x : Prop) : Prop axiom g1153 (x : Prop) : Prop axiom g1154 (x : Prop) : Prop axiom g1155 (x : Prop) : Prop axiom g1156 (x : Prop) : Prop axiom g1157 (x : Prop) : Prop axiom g1158 (x : Prop) : Prop axiom g1159 (x : Prop) : Prop axiom g1160 (x : Prop) : Prop axiom g1161 (x : Prop) : Prop axiom g1162 (x : Prop) : Prop axiom g1163 (x : Prop) : Prop axiom g1164 (x : Prop) : Prop axiom g1165 (x : Prop) : Prop axiom g1166 (x : Prop) : Prop axiom g1167 (x : Prop) : Prop axiom g1168 (x : Prop) : Prop axiom g1169 (x : Prop) : Prop axiom g1170 (x : Prop) : Prop axiom g1171 (x : Prop) : Prop axiom g1172 (x : Prop) : Prop axiom g1173 (x : Prop) : Prop axiom g1174 (x : Prop) : Prop axiom g1175 (x : Prop) : Prop axiom g1176 (x : Prop) : Prop axiom g1177 (x : Prop) : Prop axiom g1178 (x : Prop) : Prop axiom g1179 (x : Prop) : Prop axiom g1180 (x : Prop) : Prop axiom g1181 (x : Prop) : Prop axiom g1182 (x : Prop) : Prop axiom g1183 (x : Prop) : Prop axiom g1184 (x : Prop) : Prop axiom g1185 (x : Prop) : Prop axiom g1186 (x : Prop) : Prop axiom g1187 (x : Prop) : Prop axiom g1188 (x : Prop) : Prop axiom g1189 (x : Prop) : Prop axiom g1190 (x : Prop) : Prop axiom g1191 (x : Prop) : Prop axiom g1192 (x : Prop) : Prop axiom g1193 (x : Prop) : Prop axiom g1194 (x : Prop) : Prop axiom g1195 (x : Prop) : Prop axiom g1196 (x : Prop) : Prop axiom g1197 (x : Prop) : Prop axiom g1198 (x : Prop) : Prop axiom g1199 (x : Prop) : Prop axiom g1200 (x : Prop) : Prop axiom g1201 (x : Prop) : Prop axiom g1202 (x : Prop) : Prop axiom g1203 (x : Prop) : Prop axiom g1204 (x : Prop) : Prop axiom g1205 (x : Prop) : Prop axiom g1206 (x : Prop) : Prop axiom g1207 (x : Prop) : Prop axiom g1208 (x : Prop) : Prop axiom g1209 (x : Prop) : Prop axiom g1210 (x : Prop) : Prop axiom g1211 (x : Prop) : Prop axiom g1212 (x : Prop) : Prop axiom g1213 (x : Prop) : Prop axiom g1214 (x : Prop) : Prop axiom g1215 (x : Prop) : Prop axiom g1216 (x : Prop) : Prop axiom g1217 (x : Prop) : Prop axiom g1218 (x : Prop) : Prop axiom g1219 (x : Prop) : Prop axiom g1220 (x : Prop) : Prop axiom g1221 (x : Prop) : Prop axiom g1222 (x : Prop) : Prop axiom g1223 (x : Prop) : Prop axiom g1224 (x : Prop) : Prop axiom g1225 (x : Prop) : Prop axiom g1226 (x : Prop) : Prop axiom g1227 (x : Prop) : Prop axiom g1228 (x : Prop) : Prop axiom g1229 (x : Prop) : Prop axiom g1230 (x : Prop) : Prop axiom g1231 (x : Prop) : Prop axiom g1232 (x : Prop) : Prop axiom g1233 (x : Prop) : Prop axiom g1234 (x : Prop) : Prop axiom g1235 (x : Prop) : Prop axiom g1236 (x : Prop) : Prop axiom g1237 (x : Prop) : Prop axiom g1238 (x : Prop) : Prop axiom g1239 (x : Prop) : Prop axiom g1240 (x : Prop) : Prop axiom g1241 (x : Prop) : Prop axiom g1242 (x : Prop) : Prop axiom g1243 (x : Prop) : Prop axiom g1244 (x : Prop) : Prop axiom g1245 (x : Prop) : Prop axiom g1246 (x : Prop) : Prop axiom g1247 (x : Prop) : Prop axiom g1248 (x : Prop) : Prop axiom g1249 (x : Prop) : Prop axiom g1250 (x : Prop) : Prop axiom g1251 (x : Prop) : Prop axiom g1252 (x : Prop) : Prop axiom g1253 (x : Prop) : Prop axiom g1254 (x : Prop) : Prop axiom g1255 (x : Prop) : Prop axiom g1256 (x : Prop) : Prop axiom g1257 (x : Prop) : Prop axiom g1258 (x : Prop) : Prop axiom g1259 (x : Prop) : Prop axiom g1260 (x : Prop) : Prop axiom g1261 (x : Prop) : Prop axiom g1262 (x : Prop) : Prop axiom g1263 (x : Prop) : Prop axiom g1264 (x : Prop) : Prop axiom g1265 (x : Prop) : Prop axiom g1266 (x : Prop) : Prop axiom g1267 (x : Prop) : Prop axiom g1268 (x : Prop) : Prop axiom g1269 (x : Prop) : Prop axiom g1270 (x : Prop) : Prop axiom g1271 (x : Prop) : Prop axiom g1272 (x : Prop) : Prop axiom g1273 (x : Prop) : Prop axiom g1274 (x : Prop) : Prop axiom g1275 (x : Prop) : Prop axiom g1276 (x : Prop) : Prop axiom g1277 (x : Prop) : Prop axiom g1278 (x : Prop) : Prop axiom g1279 (x : Prop) : Prop axiom g1280 (x : Prop) : Prop axiom g1281 (x : Prop) : Prop axiom g1282 (x : Prop) : Prop axiom g1283 (x : Prop) : Prop axiom g1284 (x : Prop) : Prop axiom g1285 (x : Prop) : Prop axiom g1286 (x : Prop) : Prop axiom g1287 (x : Prop) : Prop axiom g1288 (x : Prop) : Prop axiom g1289 (x : Prop) : Prop axiom g1290 (x : Prop) : Prop axiom g1291 (x : Prop) : Prop axiom g1292 (x : Prop) : Prop axiom g1293 (x : Prop) : Prop axiom g1294 (x : Prop) : Prop axiom g1295 (x : Prop) : Prop axiom g1296 (x : Prop) : Prop axiom g1297 (x : Prop) : Prop axiom g1298 (x : Prop) : Prop axiom g1299 (x : Prop) : Prop axiom g1300 (x : Prop) : Prop axiom g1301 (x : Prop) : Prop axiom g1302 (x : Prop) : Prop axiom g1303 (x : Prop) : Prop axiom g1304 (x : Prop) : Prop axiom g1305 (x : Prop) : Prop axiom g1306 (x : Prop) : Prop axiom g1307 (x : Prop) : Prop axiom g1308 (x : Prop) : Prop axiom g1309 (x : Prop) : Prop axiom g1310 (x : Prop) : Prop axiom g1311 (x : Prop) : Prop axiom g1312 (x : Prop) : Prop axiom g1313 (x : Prop) : Prop axiom g1314 (x : Prop) : Prop axiom g1315 (x : Prop) : Prop axiom g1316 (x : Prop) : Prop axiom g1317 (x : Prop) : Prop axiom g1318 (x : Prop) : Prop axiom g1319 (x : Prop) : Prop axiom g1320 (x : Prop) : Prop axiom g1321 (x : Prop) : Prop axiom g1322 (x : Prop) : Prop axiom g1323 (x : Prop) : Prop axiom g1324 (x : Prop) : Prop axiom g1325 (x : Prop) : Prop axiom g1326 (x : Prop) : Prop axiom g1327 (x : Prop) : Prop axiom g1328 (x : Prop) : Prop axiom g1329 (x : Prop) : Prop axiom g1330 (x : Prop) : Prop axiom g1331 (x : Prop) : Prop axiom g1332 (x : Prop) : Prop axiom g1333 (x : Prop) : Prop axiom g1334 (x : Prop) : Prop axiom g1335 (x : Prop) : Prop axiom g1336 (x : Prop) : Prop axiom g1337 (x : Prop) : Prop axiom g1338 (x : Prop) : Prop axiom g1339 (x : Prop) : Prop axiom g1340 (x : Prop) : Prop axiom g1341 (x : Prop) : Prop axiom g1342 (x : Prop) : Prop axiom g1343 (x : Prop) : Prop axiom g1344 (x : Prop) : Prop axiom g1345 (x : Prop) : Prop axiom g1346 (x : Prop) : Prop axiom g1347 (x : Prop) : Prop axiom g1348 (x : Prop) : Prop axiom g1349 (x : Prop) : Prop axiom g1350 (x : Prop) : Prop axiom g1351 (x : Prop) : Prop axiom g1352 (x : Prop) : Prop axiom g1353 (x : Prop) : Prop axiom g1354 (x : Prop) : Prop axiom g1355 (x : Prop) : Prop axiom g1356 (x : Prop) : Prop axiom g1357 (x : Prop) : Prop axiom g1358 (x : Prop) : Prop axiom g1359 (x : Prop) : Prop axiom g1360 (x : Prop) : Prop axiom g1361 (x : Prop) : Prop axiom g1362 (x : Prop) : Prop axiom g1363 (x : Prop) : Prop axiom g1364 (x : Prop) : Prop axiom g1365 (x : Prop) : Prop axiom g1366 (x : Prop) : Prop axiom g1367 (x : Prop) : Prop axiom g1368 (x : Prop) : Prop axiom g1369 (x : Prop) : Prop axiom g1370 (x : Prop) : Prop axiom g1371 (x : Prop) : Prop axiom g1372 (x : Prop) : Prop axiom g1373 (x : Prop) : Prop axiom g1374 (x : Prop) : Prop axiom g1375 (x : Prop) : Prop axiom g1376 (x : Prop) : Prop axiom g1377 (x : Prop) : Prop axiom g1378 (x : Prop) : Prop axiom g1379 (x : Prop) : Prop axiom g1380 (x : Prop) : Prop axiom g1381 (x : Prop) : Prop axiom g1382 (x : Prop) : Prop axiom g1383 (x : Prop) : Prop axiom g1384 (x : Prop) : Prop axiom g1385 (x : Prop) : Prop axiom g1386 (x : Prop) : Prop axiom g1387 (x : Prop) : Prop axiom g1388 (x : Prop) : Prop axiom g1389 (x : Prop) : Prop axiom g1390 (x : Prop) : Prop axiom g1391 (x : Prop) : Prop axiom g1392 (x : Prop) : Prop axiom g1393 (x : Prop) : Prop axiom g1394 (x : Prop) : Prop axiom g1395 (x : Prop) : Prop axiom g1396 (x : Prop) : Prop axiom g1397 (x : Prop) : Prop axiom g1398 (x : Prop) : Prop axiom g1399 (x : Prop) : Prop axiom g1400 (x : Prop) : Prop axiom g1401 (x : Prop) : Prop axiom g1402 (x : Prop) : Prop axiom g1403 (x : Prop) : Prop axiom g1404 (x : Prop) : Prop axiom g1405 (x : Prop) : Prop axiom g1406 (x : Prop) : Prop axiom g1407 (x : Prop) : Prop axiom g1408 (x : Prop) : Prop axiom g1409 (x : Prop) : Prop axiom g1410 (x : Prop) : Prop axiom g1411 (x : Prop) : Prop axiom g1412 (x : Prop) : Prop axiom g1413 (x : Prop) : Prop axiom g1414 (x : Prop) : Prop axiom g1415 (x : Prop) : Prop axiom g1416 (x : Prop) : Prop axiom g1417 (x : Prop) : Prop axiom g1418 (x : Prop) : Prop axiom g1419 (x : Prop) : Prop axiom g1420 (x : Prop) : Prop axiom g1421 (x : Prop) : Prop axiom g1422 (x : Prop) : Prop axiom g1423 (x : Prop) : Prop axiom g1424 (x : Prop) : Prop axiom g1425 (x : Prop) : Prop axiom g1426 (x : Prop) : Prop axiom g1427 (x : Prop) : Prop axiom g1428 (x : Prop) : Prop axiom g1429 (x : Prop) : Prop axiom g1430 (x : Prop) : Prop axiom g1431 (x : Prop) : Prop axiom g1432 (x : Prop) : Prop axiom g1433 (x : Prop) : Prop axiom g1434 (x : Prop) : Prop axiom g1435 (x : Prop) : Prop axiom g1436 (x : Prop) : Prop axiom g1437 (x : Prop) : Prop axiom g1438 (x : Prop) : Prop axiom g1439 (x : Prop) : Prop axiom g1440 (x : Prop) : Prop axiom g1441 (x : Prop) : Prop axiom g1442 (x : Prop) : Prop axiom g1443 (x : Prop) : Prop axiom g1444 (x : Prop) : Prop axiom g1445 (x : Prop) : Prop axiom g1446 (x : Prop) : Prop axiom g1447 (x : Prop) : Prop axiom g1448 (x : Prop) : Prop axiom g1449 (x : Prop) : Prop axiom g1450 (x : Prop) : Prop axiom g1451 (x : Prop) : Prop axiom g1452 (x : Prop) : Prop axiom g1453 (x : Prop) : Prop axiom g1454 (x : Prop) : Prop axiom g1455 (x : Prop) : Prop axiom g1456 (x : Prop) : Prop axiom g1457 (x : Prop) : Prop axiom g1458 (x : Prop) : Prop axiom g1459 (x : Prop) : Prop axiom g1460 (x : Prop) : Prop axiom g1461 (x : Prop) : Prop axiom g1462 (x : Prop) : Prop axiom g1463 (x : Prop) : Prop axiom g1464 (x : Prop) : Prop axiom g1465 (x : Prop) : Prop axiom g1466 (x : Prop) : Prop axiom g1467 (x : Prop) : Prop axiom g1468 (x : Prop) : Prop axiom g1469 (x : Prop) : Prop axiom g1470 (x : Prop) : Prop axiom g1471 (x : Prop) : Prop axiom g1472 (x : Prop) : Prop axiom g1473 (x : Prop) : Prop axiom g1474 (x : Prop) : Prop axiom g1475 (x : Prop) : Prop axiom g1476 (x : Prop) : Prop axiom g1477 (x : Prop) : Prop axiom g1478 (x : Prop) : Prop axiom g1479 (x : Prop) : Prop axiom g1480 (x : Prop) : Prop axiom g1481 (x : Prop) : Prop axiom g1482 (x : Prop) : Prop axiom g1483 (x : Prop) : Prop axiom g1484 (x : Prop) : Prop axiom g1485 (x : Prop) : Prop axiom g1486 (x : Prop) : Prop axiom g1487 (x : Prop) : Prop axiom g1488 (x : Prop) : Prop axiom g1489 (x : Prop) : Prop axiom g1490 (x : Prop) : Prop axiom g1491 (x : Prop) : Prop axiom g1492 (x : Prop) : Prop axiom g1493 (x : Prop) : Prop axiom g1494 (x : Prop) : Prop axiom g1495 (x : Prop) : Prop axiom g1496 (x : Prop) : Prop axiom g1497 (x : Prop) : Prop axiom g1498 (x : Prop) : Prop axiom g1499 (x : Prop) : Prop axiom g1500 (x : Prop) : Prop axiom g1501 (x : Prop) : Prop axiom g1502 (x : Prop) : Prop axiom g1503 (x : Prop) : Prop axiom g1504 (x : Prop) : Prop axiom g1505 (x : Prop) : Prop axiom g1506 (x : Prop) : Prop axiom g1507 (x : Prop) : Prop axiom g1508 (x : Prop) : Prop axiom g1509 (x : Prop) : Prop axiom g1510 (x : Prop) : Prop axiom g1511 (x : Prop) : Prop axiom g1512 (x : Prop) : Prop axiom g1513 (x : Prop) : Prop axiom g1514 (x : Prop) : Prop axiom g1515 (x : Prop) : Prop axiom g1516 (x : Prop) : Prop axiom g1517 (x : Prop) : Prop axiom g1518 (x : Prop) : Prop axiom g1519 (x : Prop) : Prop axiom g1520 (x : Prop) : Prop axiom g1521 (x : Prop) : Prop axiom g1522 (x : Prop) : Prop axiom g1523 (x : Prop) : Prop axiom g1524 (x : Prop) : Prop axiom g1525 (x : Prop) : Prop axiom g1526 (x : Prop) : Prop axiom g1527 (x : Prop) : Prop axiom g1528 (x : Prop) : Prop axiom g1529 (x : Prop) : Prop axiom g1530 (x : Prop) : Prop axiom g1531 (x : Prop) : Prop axiom g1532 (x : Prop) : Prop axiom g1533 (x : Prop) : Prop axiom g1534 (x : Prop) : Prop axiom g1535 (x : Prop) : Prop axiom g1536 (x : Prop) : Prop axiom g1537 (x : Prop) : Prop axiom g1538 (x : Prop) : Prop axiom g1539 (x : Prop) : Prop axiom g1540 (x : Prop) : Prop axiom g1541 (x : Prop) : Prop axiom g1542 (x : Prop) : Prop axiom g1543 (x : Prop) : Prop axiom g1544 (x : Prop) : Prop axiom g1545 (x : Prop) : Prop axiom g1546 (x : Prop) : Prop axiom g1547 (x : Prop) : Prop axiom g1548 (x : Prop) : Prop axiom g1549 (x : Prop) : Prop axiom g1550 (x : Prop) : Prop axiom g1551 (x : Prop) : Prop axiom g1552 (x : Prop) : Prop axiom g1553 (x : Prop) : Prop axiom g1554 (x : Prop) : Prop axiom g1555 (x : Prop) : Prop axiom g1556 (x : Prop) : Prop axiom g1557 (x : Prop) : Prop axiom g1558 (x : Prop) : Prop axiom g1559 (x : Prop) : Prop axiom g1560 (x : Prop) : Prop axiom g1561 (x : Prop) : Prop axiom g1562 (x : Prop) : Prop axiom g1563 (x : Prop) : Prop axiom g1564 (x : Prop) : Prop axiom g1565 (x : Prop) : Prop axiom g1566 (x : Prop) : Prop axiom g1567 (x : Prop) : Prop axiom g1568 (x : Prop) : Prop axiom g1569 (x : Prop) : Prop axiom g1570 (x : Prop) : Prop axiom g1571 (x : Prop) : Prop axiom g1572 (x : Prop) : Prop axiom g1573 (x : Prop) : Prop axiom g1574 (x : Prop) : Prop axiom g1575 (x : Prop) : Prop axiom g1576 (x : Prop) : Prop axiom g1577 (x : Prop) : Prop axiom g1578 (x : Prop) : Prop axiom g1579 (x : Prop) : Prop axiom g1580 (x : Prop) : Prop axiom g1581 (x : Prop) : Prop axiom g1582 (x : Prop) : Prop axiom g1583 (x : Prop) : Prop axiom g1584 (x : Prop) : Prop axiom g1585 (x : Prop) : Prop axiom g1586 (x : Prop) : Prop axiom g1587 (x : Prop) : Prop axiom g1588 (x : Prop) : Prop axiom g1589 (x : Prop) : Prop axiom g1590 (x : Prop) : Prop axiom g1591 (x : Prop) : Prop axiom g1592 (x : Prop) : Prop axiom g1593 (x : Prop) : Prop axiom g1594 (x : Prop) : Prop axiom g1595 (x : Prop) : Prop axiom g1596 (x : Prop) : Prop axiom g1597 (x : Prop) : Prop axiom g1598 (x : Prop) : Prop axiom g1599 (x : Prop) : Prop axiom g1600 (x : Prop) : Prop axiom g1601 (x : Prop) : Prop axiom g1602 (x : Prop) : Prop axiom g1603 (x : Prop) : Prop axiom g1604 (x : Prop) : Prop axiom g1605 (x : Prop) : Prop axiom g1606 (x : Prop) : Prop axiom g1607 (x : Prop) : Prop axiom g1608 (x : Prop) : Prop axiom g1609 (x : Prop) : Prop axiom g1610 (x : Prop) : Prop axiom g1611 (x : Prop) : Prop axiom g1612 (x : Prop) : Prop axiom g1613 (x : Prop) : Prop axiom g1614 (x : Prop) : Prop axiom g1615 (x : Prop) : Prop axiom g1616 (x : Prop) : Prop axiom g1617 (x : Prop) : Prop axiom g1618 (x : Prop) : Prop axiom g1619 (x : Prop) : Prop axiom g1620 (x : Prop) : Prop axiom g1621 (x : Prop) : Prop axiom g1622 (x : Prop) : Prop axiom g1623 (x : Prop) : Prop axiom g1624 (x : Prop) : Prop axiom g1625 (x : Prop) : Prop axiom g1626 (x : Prop) : Prop axiom g1627 (x : Prop) : Prop axiom g1628 (x : Prop) : Prop axiom g1629 (x : Prop) : Prop axiom g1630 (x : Prop) : Prop axiom g1631 (x : Prop) : Prop axiom g1632 (x : Prop) : Prop axiom g1633 (x : Prop) : Prop axiom g1634 (x : Prop) : Prop axiom g1635 (x : Prop) : Prop axiom g1636 (x : Prop) : Prop axiom g1637 (x : Prop) : Prop axiom g1638 (x : Prop) : Prop axiom g1639 (x : Prop) : Prop axiom g1640 (x : Prop) : Prop axiom g1641 (x : Prop) : Prop axiom g1642 (x : Prop) : Prop axiom g1643 (x : Prop) : Prop axiom g1644 (x : Prop) : Prop axiom g1645 (x : Prop) : Prop axiom g1646 (x : Prop) : Prop axiom g1647 (x : Prop) : Prop axiom g1648 (x : Prop) : Prop axiom g1649 (x : Prop) : Prop axiom g1650 (x : Prop) : Prop axiom g1651 (x : Prop) : Prop axiom g1652 (x : Prop) : Prop axiom g1653 (x : Prop) : Prop axiom g1654 (x : Prop) : Prop axiom g1655 (x : Prop) : Prop axiom g1656 (x : Prop) : Prop axiom g1657 (x : Prop) : Prop axiom g1658 (x : Prop) : Prop axiom g1659 (x : Prop) : Prop axiom g1660 (x : Prop) : Prop axiom g1661 (x : Prop) : Prop axiom g1662 (x : Prop) : Prop axiom g1663 (x : Prop) : Prop axiom g1664 (x : Prop) : Prop axiom g1665 (x : Prop) : Prop axiom g1666 (x : Prop) : Prop axiom g1667 (x : Prop) : Prop axiom g1668 (x : Prop) : Prop axiom g1669 (x : Prop) : Prop axiom g1670 (x : Prop) : Prop axiom g1671 (x : Prop) : Prop axiom g1672 (x : Prop) : Prop axiom g1673 (x : Prop) : Prop axiom g1674 (x : Prop) : Prop axiom g1675 (x : Prop) : Prop axiom g1676 (x : Prop) : Prop axiom g1677 (x : Prop) : Prop axiom g1678 (x : Prop) : Prop axiom g1679 (x : Prop) : Prop axiom g1680 (x : Prop) : Prop axiom g1681 (x : Prop) : Prop axiom g1682 (x : Prop) : Prop axiom g1683 (x : Prop) : Prop axiom g1684 (x : Prop) : Prop axiom g1685 (x : Prop) : Prop axiom g1686 (x : Prop) : Prop axiom g1687 (x : Prop) : Prop axiom g1688 (x : Prop) : Prop axiom g1689 (x : Prop) : Prop axiom g1690 (x : Prop) : Prop axiom g1691 (x : Prop) : Prop axiom g1692 (x : Prop) : Prop axiom g1693 (x : Prop) : Prop axiom g1694 (x : Prop) : Prop axiom g1695 (x : Prop) : Prop axiom g1696 (x : Prop) : Prop axiom g1697 (x : Prop) : Prop axiom g1698 (x : Prop) : Prop axiom g1699 (x : Prop) : Prop axiom g1700 (x : Prop) : Prop axiom g1701 (x : Prop) : Prop axiom g1702 (x : Prop) : Prop axiom g1703 (x : Prop) : Prop axiom g1704 (x : Prop) : Prop axiom g1705 (x : Prop) : Prop axiom g1706 (x : Prop) : Prop axiom g1707 (x : Prop) : Prop axiom g1708 (x : Prop) : Prop axiom g1709 (x : Prop) : Prop axiom g1710 (x : Prop) : Prop axiom g1711 (x : Prop) : Prop axiom g1712 (x : Prop) : Prop axiom g1713 (x : Prop) : Prop axiom g1714 (x : Prop) : Prop axiom g1715 (x : Prop) : Prop axiom g1716 (x : Prop) : Prop axiom g1717 (x : Prop) : Prop axiom g1718 (x : Prop) : Prop axiom g1719 (x : Prop) : Prop axiom g1720 (x : Prop) : Prop axiom g1721 (x : Prop) : Prop axiom g1722 (x : Prop) : Prop axiom g1723 (x : Prop) : Prop axiom g1724 (x : Prop) : Prop axiom g1725 (x : Prop) : Prop axiom g1726 (x : Prop) : Prop axiom g1727 (x : Prop) : Prop axiom g1728 (x : Prop) : Prop axiom g1729 (x : Prop) : Prop axiom g1730 (x : Prop) : Prop axiom g1731 (x : Prop) : Prop axiom g1732 (x : Prop) : Prop axiom g1733 (x : Prop) : Prop axiom g1734 (x : Prop) : Prop axiom g1735 (x : Prop) : Prop axiom g1736 (x : Prop) : Prop axiom g1737 (x : Prop) : Prop axiom g1738 (x : Prop) : Prop axiom g1739 (x : Prop) : Prop axiom g1740 (x : Prop) : Prop axiom g1741 (x : Prop) : Prop axiom g1742 (x : Prop) : Prop axiom g1743 (x : Prop) : Prop axiom g1744 (x : Prop) : Prop axiom g1745 (x : Prop) : Prop axiom g1746 (x : Prop) : Prop axiom g1747 (x : Prop) : Prop axiom g1748 (x : Prop) : Prop axiom g1749 (x : Prop) : Prop axiom g1750 (x : Prop) : Prop axiom g1751 (x : Prop) : Prop axiom g1752 (x : Prop) : Prop axiom g1753 (x : Prop) : Prop axiom g1754 (x : Prop) : Prop axiom g1755 (x : Prop) : Prop axiom g1756 (x : Prop) : Prop axiom g1757 (x : Prop) : Prop axiom g1758 (x : Prop) : Prop axiom g1759 (x : Prop) : Prop axiom g1760 (x : Prop) : Prop axiom g1761 (x : Prop) : Prop axiom g1762 (x : Prop) : Prop axiom g1763 (x : Prop) : Prop axiom g1764 (x : Prop) : Prop axiom g1765 (x : Prop) : Prop axiom g1766 (x : Prop) : Prop axiom g1767 (x : Prop) : Prop axiom g1768 (x : Prop) : Prop axiom g1769 (x : Prop) : Prop axiom g1770 (x : Prop) : Prop axiom g1771 (x : Prop) : Prop axiom g1772 (x : Prop) : Prop axiom g1773 (x : Prop) : Prop axiom g1774 (x : Prop) : Prop axiom g1775 (x : Prop) : Prop axiom g1776 (x : Prop) : Prop axiom g1777 (x : Prop) : Prop axiom g1778 (x : Prop) : Prop axiom g1779 (x : Prop) : Prop axiom g1780 (x : Prop) : Prop axiom g1781 (x : Prop) : Prop axiom g1782 (x : Prop) : Prop axiom g1783 (x : Prop) : Prop axiom g1784 (x : Prop) : Prop axiom g1785 (x : Prop) : Prop axiom g1786 (x : Prop) : Prop axiom g1787 (x : Prop) : Prop axiom g1788 (x : Prop) : Prop axiom g1789 (x : Prop) : Prop axiom g1790 (x : Prop) : Prop axiom g1791 (x : Prop) : Prop axiom g1792 (x : Prop) : Prop axiom g1793 (x : Prop) : Prop axiom g1794 (x : Prop) : Prop axiom g1795 (x : Prop) : Prop axiom g1796 (x : Prop) : Prop axiom g1797 (x : Prop) : Prop axiom g1798 (x : Prop) : Prop axiom g1799 (x : Prop) : Prop axiom g1800 (x : Prop) : Prop axiom g1801 (x : Prop) : Prop axiom g1802 (x : Prop) : Prop axiom g1803 (x : Prop) : Prop axiom g1804 (x : Prop) : Prop axiom g1805 (x : Prop) : Prop axiom g1806 (x : Prop) : Prop axiom g1807 (x : Prop) : Prop axiom g1808 (x : Prop) : Prop axiom g1809 (x : Prop) : Prop axiom g1810 (x : Prop) : Prop axiom g1811 (x : Prop) : Prop axiom g1812 (x : Prop) : Prop axiom g1813 (x : Prop) : Prop axiom g1814 (x : Prop) : Prop axiom g1815 (x : Prop) : Prop axiom g1816 (x : Prop) : Prop axiom g1817 (x : Prop) : Prop axiom g1818 (x : Prop) : Prop axiom g1819 (x : Prop) : Prop axiom g1820 (x : Prop) : Prop axiom g1821 (x : Prop) : Prop axiom g1822 (x : Prop) : Prop axiom g1823 (x : Prop) : Prop axiom g1824 (x : Prop) : Prop axiom g1825 (x : Prop) : Prop axiom g1826 (x : Prop) : Prop axiom g1827 (x : Prop) : Prop axiom g1828 (x : Prop) : Prop axiom g1829 (x : Prop) : Prop axiom g1830 (x : Prop) : Prop axiom g1831 (x : Prop) : Prop axiom g1832 (x : Prop) : Prop axiom g1833 (x : Prop) : Prop axiom g1834 (x : Prop) : Prop axiom g1835 (x : Prop) : Prop axiom g1836 (x : Prop) : Prop axiom g1837 (x : Prop) : Prop axiom g1838 (x : Prop) : Prop axiom g1839 (x : Prop) : Prop axiom g1840 (x : Prop) : Prop axiom g1841 (x : Prop) : Prop axiom g1842 (x : Prop) : Prop axiom g1843 (x : Prop) : Prop axiom g1844 (x : Prop) : Prop axiom g1845 (x : Prop) : Prop axiom g1846 (x : Prop) : Prop axiom g1847 (x : Prop) : Prop axiom g1848 (x : Prop) : Prop axiom g1849 (x : Prop) : Prop axiom g1850 (x : Prop) : Prop axiom g1851 (x : Prop) : Prop axiom g1852 (x : Prop) : Prop axiom g1853 (x : Prop) : Prop axiom g1854 (x : Prop) : Prop axiom g1855 (x : Prop) : Prop axiom g1856 (x : Prop) : Prop axiom g1857 (x : Prop) : Prop axiom g1858 (x : Prop) : Prop axiom g1859 (x : Prop) : Prop axiom g1860 (x : Prop) : Prop axiom g1861 (x : Prop) : Prop axiom g1862 (x : Prop) : Prop axiom g1863 (x : Prop) : Prop axiom g1864 (x : Prop) : Prop axiom g1865 (x : Prop) : Prop axiom g1866 (x : Prop) : Prop axiom g1867 (x : Prop) : Prop axiom g1868 (x : Prop) : Prop axiom g1869 (x : Prop) : Prop axiom g1870 (x : Prop) : Prop axiom g1871 (x : Prop) : Prop axiom g1872 (x : Prop) : Prop axiom g1873 (x : Prop) : Prop axiom g1874 (x : Prop) : Prop axiom g1875 (x : Prop) : Prop axiom g1876 (x : Prop) : Prop axiom g1877 (x : Prop) : Prop axiom g1878 (x : Prop) : Prop axiom g1879 (x : Prop) : Prop axiom g1880 (x : Prop) : Prop axiom g1881 (x : Prop) : Prop axiom g1882 (x : Prop) : Prop axiom g1883 (x : Prop) : Prop axiom g1884 (x : Prop) : Prop axiom g1885 (x : Prop) : Prop axiom g1886 (x : Prop) : Prop axiom g1887 (x : Prop) : Prop axiom g1888 (x : Prop) : Prop axiom g1889 (x : Prop) : Prop axiom g1890 (x : Prop) : Prop axiom g1891 (x : Prop) : Prop axiom g1892 (x : Prop) : Prop axiom g1893 (x : Prop) : Prop axiom g1894 (x : Prop) : Prop axiom g1895 (x : Prop) : Prop axiom g1896 (x : Prop) : Prop axiom g1897 (x : Prop) : Prop axiom g1898 (x : Prop) : Prop axiom g1899 (x : Prop) : Prop axiom g1900 (x : Prop) : Prop axiom g1901 (x : Prop) : Prop axiom g1902 (x : Prop) : Prop axiom g1903 (x : Prop) : Prop axiom g1904 (x : Prop) : Prop axiom g1905 (x : Prop) : Prop axiom g1906 (x : Prop) : Prop axiom g1907 (x : Prop) : Prop axiom g1908 (x : Prop) : Prop axiom g1909 (x : Prop) : Prop axiom g1910 (x : Prop) : Prop axiom g1911 (x : Prop) : Prop axiom g1912 (x : Prop) : Prop axiom g1913 (x : Prop) : Prop axiom g1914 (x : Prop) : Prop axiom g1915 (x : Prop) : Prop axiom g1916 (x : Prop) : Prop axiom g1917 (x : Prop) : Prop axiom g1918 (x : Prop) : Prop axiom g1919 (x : Prop) : Prop axiom g1920 (x : Prop) : Prop axiom g1921 (x : Prop) : Prop axiom g1922 (x : Prop) : Prop axiom g1923 (x : Prop) : Prop axiom g1924 (x : Prop) : Prop axiom g1925 (x : Prop) : Prop axiom g1926 (x : Prop) : Prop axiom g1927 (x : Prop) : Prop axiom g1928 (x : Prop) : Prop axiom g1929 (x : Prop) : Prop axiom g1930 (x : Prop) : Prop axiom g1931 (x : Prop) : Prop axiom g1932 (x : Prop) : Prop axiom g1933 (x : Prop) : Prop axiom g1934 (x : Prop) : Prop axiom g1935 (x : Prop) : Prop axiom g1936 (x : Prop) : Prop axiom g1937 (x : Prop) : Prop axiom g1938 (x : Prop) : Prop axiom g1939 (x : Prop) : Prop axiom g1940 (x : Prop) : Prop axiom g1941 (x : Prop) : Prop axiom g1942 (x : Prop) : Prop axiom g1943 (x : Prop) : Prop axiom g1944 (x : Prop) : Prop axiom g1945 (x : Prop) : Prop axiom g1946 (x : Prop) : Prop axiom g1947 (x : Prop) : Prop axiom g1948 (x : Prop) : Prop axiom g1949 (x : Prop) : Prop axiom g1950 (x : Prop) : Prop axiom g1951 (x : Prop) : Prop axiom g1952 (x : Prop) : Prop axiom g1953 (x : Prop) : Prop axiom g1954 (x : Prop) : Prop axiom g1955 (x : Prop) : Prop axiom g1956 (x : Prop) : Prop axiom g1957 (x : Prop) : Prop axiom g1958 (x : Prop) : Prop axiom g1959 (x : Prop) : Prop axiom g1960 (x : Prop) : Prop axiom g1961 (x : Prop) : Prop axiom g1962 (x : Prop) : Prop axiom g1963 (x : Prop) : Prop axiom g1964 (x : Prop) : Prop axiom g1965 (x : Prop) : Prop axiom g1966 (x : Prop) : Prop axiom g1967 (x : Prop) : Prop axiom g1968 (x : Prop) : Prop axiom g1969 (x : Prop) : Prop axiom g1970 (x : Prop) : Prop axiom g1971 (x : Prop) : Prop axiom g1972 (x : Prop) : Prop axiom g1973 (x : Prop) : Prop axiom g1974 (x : Prop) : Prop axiom g1975 (x : Prop) : Prop axiom g1976 (x : Prop) : Prop axiom g1977 (x : Prop) : Prop axiom g1978 (x : Prop) : Prop axiom g1979 (x : Prop) : Prop axiom g1980 (x : Prop) : Prop axiom g1981 (x : Prop) : Prop axiom g1982 (x : Prop) : Prop axiom g1983 (x : Prop) : Prop axiom g1984 (x : Prop) : Prop axiom g1985 (x : Prop) : Prop axiom g1986 (x : Prop) : Prop axiom g1987 (x : Prop) : Prop axiom g1988 (x : Prop) : Prop axiom g1989 (x : Prop) : Prop axiom g1990 (x : Prop) : Prop axiom g1991 (x : Prop) : Prop axiom g1992 (x : Prop) : Prop axiom g1993 (x : Prop) : Prop axiom g1994 (x : Prop) : Prop axiom g1995 (x : Prop) : Prop axiom g1996 (x : Prop) : Prop axiom g1997 (x : Prop) : Prop axiom g1998 (x : Prop) : Prop axiom g1999 (x : Prop) : Prop @[simp] axiom s0 (x : Prop) : f (g1 x) = f (g0 x) @[simp] axiom s1 (x : Prop) : f (g2 x) = f (g1 x) @[simp] axiom s2 (x : Prop) : f (g3 x) = f (g2 x) @[simp] axiom s3 (x : Prop) : f (g4 x) = f (g3 x) @[simp] axiom s4 (x : Prop) : f (g5 x) = f (g4 x) @[simp] axiom s5 (x : Prop) : f (g6 x) = f (g5 x) @[simp] axiom s6 (x : Prop) : f (g7 x) = f (g6 x) @[simp] axiom s7 (x : Prop) : f (g8 x) = f (g7 x) @[simp] axiom s8 (x : Prop) : f (g9 x) = f (g8 x) @[simp] axiom s9 (x : Prop) : f (g10 x) = f (g9 x) @[simp] axiom s10 (x : Prop) : f (g11 x) = f (g10 x) @[simp] axiom s11 (x : Prop) : f (g12 x) = f (g11 x) @[simp] axiom s12 (x : Prop) : f (g13 x) = f (g12 x) @[simp] axiom s13 (x : Prop) : f (g14 x) = f (g13 x) @[simp] axiom s14 (x : Prop) : f (g15 x) = f (g14 x) @[simp] axiom s15 (x : Prop) : f (g16 x) = f (g15 x) @[simp] axiom s16 (x : Prop) : f (g17 x) = f (g16 x) @[simp] axiom s17 (x : Prop) : f (g18 x) = f (g17 x) @[simp] axiom s18 (x : Prop) : f (g19 x) = f (g18 x) @[simp] axiom s19 (x : Prop) : f (g20 x) = f (g19 x) @[simp] axiom s20 (x : Prop) : f (g21 x) = f (g20 x) @[simp] axiom s21 (x : Prop) : f (g22 x) = f (g21 x) @[simp] axiom s22 (x : Prop) : f (g23 x) = f (g22 x) @[simp] axiom s23 (x : Prop) : f (g24 x) = f (g23 x) @[simp] axiom s24 (x : Prop) : f (g25 x) = f (g24 x) @[simp] axiom s25 (x : Prop) : f (g26 x) = f (g25 x) @[simp] axiom s26 (x : Prop) : f (g27 x) = f (g26 x) @[simp] axiom s27 (x : Prop) : f (g28 x) = f (g27 x) @[simp] axiom s28 (x : Prop) : f (g29 x) = f (g28 x) @[simp] axiom s29 (x : Prop) : f (g30 x) = f (g29 x) @[simp] axiom s30 (x : Prop) : f (g31 x) = f (g30 x) @[simp] axiom s31 (x : Prop) : f (g32 x) = f (g31 x) @[simp] axiom s32 (x : Prop) : f (g33 x) = f (g32 x) @[simp] axiom s33 (x : Prop) : f (g34 x) = f (g33 x) @[simp] axiom s34 (x : Prop) : f (g35 x) = f (g34 x) @[simp] axiom s35 (x : Prop) : f (g36 x) = f (g35 x) @[simp] axiom s36 (x : Prop) : f (g37 x) = f (g36 x) @[simp] axiom s37 (x : Prop) : f (g38 x) = f (g37 x) @[simp] axiom s38 (x : Prop) : f (g39 x) = f (g38 x) @[simp] axiom s39 (x : Prop) : f (g40 x) = f (g39 x) @[simp] axiom s40 (x : Prop) : f (g41 x) = f (g40 x) @[simp] axiom s41 (x : Prop) : f (g42 x) = f (g41 x) @[simp] axiom s42 (x : Prop) : f (g43 x) = f (g42 x) @[simp] axiom s43 (x : Prop) : f (g44 x) = f (g43 x) @[simp] axiom s44 (x : Prop) : f (g45 x) = f (g44 x) @[simp] axiom s45 (x : Prop) : f (g46 x) = f (g45 x) @[simp] axiom s46 (x : Prop) : f (g47 x) = f (g46 x) @[simp] axiom s47 (x : Prop) : f (g48 x) = f (g47 x) @[simp] axiom s48 (x : Prop) : f (g49 x) = f (g48 x) @[simp] axiom s49 (x : Prop) : f (g50 x) = f (g49 x) @[simp] axiom s50 (x : Prop) : f (g51 x) = f (g50 x) @[simp] axiom s51 (x : Prop) : f (g52 x) = f (g51 x) @[simp] axiom s52 (x : Prop) : f (g53 x) = f (g52 x) @[simp] axiom s53 (x : Prop) : f (g54 x) = f (g53 x) @[simp] axiom s54 (x : Prop) : f (g55 x) = f (g54 x) @[simp] axiom s55 (x : Prop) : f (g56 x) = f (g55 x) @[simp] axiom s56 (x : Prop) : f (g57 x) = f (g56 x) @[simp] axiom s57 (x : Prop) : f (g58 x) = f (g57 x) @[simp] axiom s58 (x : Prop) : f (g59 x) = f (g58 x) @[simp] axiom s59 (x : Prop) : f (g60 x) = f (g59 x) @[simp] axiom s60 (x : Prop) : f (g61 x) = f (g60 x) @[simp] axiom s61 (x : Prop) : f (g62 x) = f (g61 x) @[simp] axiom s62 (x : Prop) : f (g63 x) = f (g62 x) @[simp] axiom s63 (x : Prop) : f (g64 x) = f (g63 x) @[simp] axiom s64 (x : Prop) : f (g65 x) = f (g64 x) @[simp] axiom s65 (x : Prop) : f (g66 x) = f (g65 x) @[simp] axiom s66 (x : Prop) : f (g67 x) = f (g66 x) @[simp] axiom s67 (x : Prop) : f (g68 x) = f (g67 x) @[simp] axiom s68 (x : Prop) : f (g69 x) = f (g68 x) @[simp] axiom s69 (x : Prop) : f (g70 x) = f (g69 x) @[simp] axiom s70 (x : Prop) : f (g71 x) = f (g70 x) @[simp] axiom s71 (x : Prop) : f (g72 x) = f (g71 x) @[simp] axiom s72 (x : Prop) : f (g73 x) = f (g72 x) @[simp] axiom s73 (x : Prop) : f (g74 x) = f (g73 x) @[simp] axiom s74 (x : Prop) : f (g75 x) = f (g74 x) @[simp] axiom s75 (x : Prop) : f (g76 x) = f (g75 x) @[simp] axiom s76 (x : Prop) : f (g77 x) = f (g76 x) @[simp] axiom s77 (x : Prop) : f (g78 x) = f (g77 x) @[simp] axiom s78 (x : Prop) : f (g79 x) = f (g78 x) @[simp] axiom s79 (x : Prop) : f (g80 x) = f (g79 x) @[simp] axiom s80 (x : Prop) : f (g81 x) = f (g80 x) @[simp] axiom s81 (x : Prop) : f (g82 x) = f (g81 x) @[simp] axiom s82 (x : Prop) : f (g83 x) = f (g82 x) @[simp] axiom s83 (x : Prop) : f (g84 x) = f (g83 x) @[simp] axiom s84 (x : Prop) : f (g85 x) = f (g84 x) @[simp] axiom s85 (x : Prop) : f (g86 x) = f (g85 x) @[simp] axiom s86 (x : Prop) : f (g87 x) = f (g86 x) @[simp] axiom s87 (x : Prop) : f (g88 x) = f (g87 x) @[simp] axiom s88 (x : Prop) : f (g89 x) = f (g88 x) @[simp] axiom s89 (x : Prop) : f (g90 x) = f (g89 x) @[simp] axiom s90 (x : Prop) : f (g91 x) = f (g90 x) @[simp] axiom s91 (x : Prop) : f (g92 x) = f (g91 x) @[simp] axiom s92 (x : Prop) : f (g93 x) = f (g92 x) @[simp] axiom s93 (x : Prop) : f (g94 x) = f (g93 x) @[simp] axiom s94 (x : Prop) : f (g95 x) = f (g94 x) @[simp] axiom s95 (x : Prop) : f (g96 x) = f (g95 x) @[simp] axiom s96 (x : Prop) : f (g97 x) = f (g96 x) @[simp] axiom s97 (x : Prop) : f (g98 x) = f (g97 x) @[simp] axiom s98 (x : Prop) : f (g99 x) = f (g98 x) @[simp] axiom s99 (x : Prop) : f (g100 x) = f (g99 x) @[simp] axiom s100 (x : Prop) : f (g101 x) = f (g100 x) @[simp] axiom s101 (x : Prop) : f (g102 x) = f (g101 x) @[simp] axiom s102 (x : Prop) : f (g103 x) = f (g102 x) @[simp] axiom s103 (x : Prop) : f (g104 x) = f (g103 x) @[simp] axiom s104 (x : Prop) : f (g105 x) = f (g104 x) @[simp] axiom s105 (x : Prop) : f (g106 x) = f (g105 x) @[simp] axiom s106 (x : Prop) : f (g107 x) = f (g106 x) @[simp] axiom s107 (x : Prop) : f (g108 x) = f (g107 x) @[simp] axiom s108 (x : Prop) : f (g109 x) = f (g108 x) @[simp] axiom s109 (x : Prop) : f (g110 x) = f (g109 x) @[simp] axiom s110 (x : Prop) : f (g111 x) = f (g110 x) @[simp] axiom s111 (x : Prop) : f (g112 x) = f (g111 x) @[simp] axiom s112 (x : Prop) : f (g113 x) = f (g112 x) @[simp] axiom s113 (x : Prop) : f (g114 x) = f (g113 x) @[simp] axiom s114 (x : Prop) : f (g115 x) = f (g114 x) @[simp] axiom s115 (x : Prop) : f (g116 x) = f (g115 x) @[simp] axiom s116 (x : Prop) : f (g117 x) = f (g116 x) @[simp] axiom s117 (x : Prop) : f (g118 x) = f (g117 x) @[simp] axiom s118 (x : Prop) : f (g119 x) = f (g118 x) @[simp] axiom s119 (x : Prop) : f (g120 x) = f (g119 x) @[simp] axiom s120 (x : Prop) : f (g121 x) = f (g120 x) @[simp] axiom s121 (x : Prop) : f (g122 x) = f (g121 x) @[simp] axiom s122 (x : Prop) : f (g123 x) = f (g122 x) @[simp] axiom s123 (x : Prop) : f (g124 x) = f (g123 x) @[simp] axiom s124 (x : Prop) : f (g125 x) = f (g124 x) @[simp] axiom s125 (x : Prop) : f (g126 x) = f (g125 x) @[simp] axiom s126 (x : Prop) : f (g127 x) = f (g126 x) @[simp] axiom s127 (x : Prop) : f (g128 x) = f (g127 x) @[simp] axiom s128 (x : Prop) : f (g129 x) = f (g128 x) @[simp] axiom s129 (x : Prop) : f (g130 x) = f (g129 x) @[simp] axiom s130 (x : Prop) : f (g131 x) = f (g130 x) @[simp] axiom s131 (x : Prop) : f (g132 x) = f (g131 x) @[simp] axiom s132 (x : Prop) : f (g133 x) = f (g132 x) @[simp] axiom s133 (x : Prop) : f (g134 x) = f (g133 x) @[simp] axiom s134 (x : Prop) : f (g135 x) = f (g134 x) @[simp] axiom s135 (x : Prop) : f (g136 x) = f (g135 x) @[simp] axiom s136 (x : Prop) : f (g137 x) = f (g136 x) @[simp] axiom s137 (x : Prop) : f (g138 x) = f (g137 x) @[simp] axiom s138 (x : Prop) : f (g139 x) = f (g138 x) @[simp] axiom s139 (x : Prop) : f (g140 x) = f (g139 x) @[simp] axiom s140 (x : Prop) : f (g141 x) = f (g140 x) @[simp] axiom s141 (x : Prop) : f (g142 x) = f (g141 x) @[simp] axiom s142 (x : Prop) : f (g143 x) = f (g142 x) @[simp] axiom s143 (x : Prop) : f (g144 x) = f (g143 x) @[simp] axiom s144 (x : Prop) : f (g145 x) = f (g144 x) @[simp] axiom s145 (x : Prop) : f (g146 x) = f (g145 x) @[simp] axiom s146 (x : Prop) : f (g147 x) = f (g146 x) @[simp] axiom s147 (x : Prop) : f (g148 x) = f (g147 x) @[simp] axiom s148 (x : Prop) : f (g149 x) = f (g148 x) @[simp] axiom s149 (x : Prop) : f (g150 x) = f (g149 x) @[simp] axiom s150 (x : Prop) : f (g151 x) = f (g150 x) @[simp] axiom s151 (x : Prop) : f (g152 x) = f (g151 x) @[simp] axiom s152 (x : Prop) : f (g153 x) = f (g152 x) @[simp] axiom s153 (x : Prop) : f (g154 x) = f (g153 x) @[simp] axiom s154 (x : Prop) : f (g155 x) = f (g154 x) @[simp] axiom s155 (x : Prop) : f (g156 x) = f (g155 x) @[simp] axiom s156 (x : Prop) : f (g157 x) = f (g156 x) @[simp] axiom s157 (x : Prop) : f (g158 x) = f (g157 x) @[simp] axiom s158 (x : Prop) : f (g159 x) = f (g158 x) @[simp] axiom s159 (x : Prop) : f (g160 x) = f (g159 x) @[simp] axiom s160 (x : Prop) : f (g161 x) = f (g160 x) @[simp] axiom s161 (x : Prop) : f (g162 x) = f (g161 x) @[simp] axiom s162 (x : Prop) : f (g163 x) = f (g162 x) @[simp] axiom s163 (x : Prop) : f (g164 x) = f (g163 x) @[simp] axiom s164 (x : Prop) : f (g165 x) = f (g164 x) @[simp] axiom s165 (x : Prop) : f (g166 x) = f (g165 x) @[simp] axiom s166 (x : Prop) : f (g167 x) = f (g166 x) @[simp] axiom s167 (x : Prop) : f (g168 x) = f (g167 x) @[simp] axiom s168 (x : Prop) : f (g169 x) = f (g168 x) @[simp] axiom s169 (x : Prop) : f (g170 x) = f (g169 x) @[simp] axiom s170 (x : Prop) : f (g171 x) = f (g170 x) @[simp] axiom s171 (x : Prop) : f (g172 x) = f (g171 x) @[simp] axiom s172 (x : Prop) : f (g173 x) = f (g172 x) @[simp] axiom s173 (x : Prop) : f (g174 x) = f (g173 x) @[simp] axiom s174 (x : Prop) : f (g175 x) = f (g174 x) @[simp] axiom s175 (x : Prop) : f (g176 x) = f (g175 x) @[simp] axiom s176 (x : Prop) : f (g177 x) = f (g176 x) @[simp] axiom s177 (x : Prop) : f (g178 x) = f (g177 x) @[simp] axiom s178 (x : Prop) : f (g179 x) = f (g178 x) @[simp] axiom s179 (x : Prop) : f (g180 x) = f (g179 x) @[simp] axiom s180 (x : Prop) : f (g181 x) = f (g180 x) @[simp] axiom s181 (x : Prop) : f (g182 x) = f (g181 x) @[simp] axiom s182 (x : Prop) : f (g183 x) = f (g182 x) @[simp] axiom s183 (x : Prop) : f (g184 x) = f (g183 x) @[simp] axiom s184 (x : Prop) : f (g185 x) = f (g184 x) @[simp] axiom s185 (x : Prop) : f (g186 x) = f (g185 x) @[simp] axiom s186 (x : Prop) : f (g187 x) = f (g186 x) @[simp] axiom s187 (x : Prop) : f (g188 x) = f (g187 x) @[simp] axiom s188 (x : Prop) : f (g189 x) = f (g188 x) @[simp] axiom s189 (x : Prop) : f (g190 x) = f (g189 x) @[simp] axiom s190 (x : Prop) : f (g191 x) = f (g190 x) @[simp] axiom s191 (x : Prop) : f (g192 x) = f (g191 x) @[simp] axiom s192 (x : Prop) : f (g193 x) = f (g192 x) @[simp] axiom s193 (x : Prop) : f (g194 x) = f (g193 x) @[simp] axiom s194 (x : Prop) : f (g195 x) = f (g194 x) @[simp] axiom s195 (x : Prop) : f (g196 x) = f (g195 x) @[simp] axiom s196 (x : Prop) : f (g197 x) = f (g196 x) @[simp] axiom s197 (x : Prop) : f (g198 x) = f (g197 x) @[simp] axiom s198 (x : Prop) : f (g199 x) = f (g198 x) @[simp] axiom s199 (x : Prop) : f (g200 x) = f (g199 x) @[simp] axiom s200 (x : Prop) : f (g201 x) = f (g200 x) @[simp] axiom s201 (x : Prop) : f (g202 x) = f (g201 x) @[simp] axiom s202 (x : Prop) : f (g203 x) = f (g202 x) @[simp] axiom s203 (x : Prop) : f (g204 x) = f (g203 x) @[simp] axiom s204 (x : Prop) : f (g205 x) = f (g204 x) @[simp] axiom s205 (x : Prop) : f (g206 x) = f (g205 x) @[simp] axiom s206 (x : Prop) : f (g207 x) = f (g206 x) @[simp] axiom s207 (x : Prop) : f (g208 x) = f (g207 x) @[simp] axiom s208 (x : Prop) : f (g209 x) = f (g208 x) @[simp] axiom s209 (x : Prop) : f (g210 x) = f (g209 x) @[simp] axiom s210 (x : Prop) : f (g211 x) = f (g210 x) @[simp] axiom s211 (x : Prop) : f (g212 x) = f (g211 x) @[simp] axiom s212 (x : Prop) : f (g213 x) = f (g212 x) @[simp] axiom s213 (x : Prop) : f (g214 x) = f (g213 x) @[simp] axiom s214 (x : Prop) : f (g215 x) = f (g214 x) @[simp] axiom s215 (x : Prop) : f (g216 x) = f (g215 x) @[simp] axiom s216 (x : Prop) : f (g217 x) = f (g216 x) @[simp] axiom s217 (x : Prop) : f (g218 x) = f (g217 x) @[simp] axiom s218 (x : Prop) : f (g219 x) = f (g218 x) @[simp] axiom s219 (x : Prop) : f (g220 x) = f (g219 x) @[simp] axiom s220 (x : Prop) : f (g221 x) = f (g220 x) @[simp] axiom s221 (x : Prop) : f (g222 x) = f (g221 x) @[simp] axiom s222 (x : Prop) : f (g223 x) = f (g222 x) @[simp] axiom s223 (x : Prop) : f (g224 x) = f (g223 x) @[simp] axiom s224 (x : Prop) : f (g225 x) = f (g224 x) @[simp] axiom s225 (x : Prop) : f (g226 x) = f (g225 x) @[simp] axiom s226 (x : Prop) : f (g227 x) = f (g226 x) @[simp] axiom s227 (x : Prop) : f (g228 x) = f (g227 x) @[simp] axiom s228 (x : Prop) : f (g229 x) = f (g228 x) @[simp] axiom s229 (x : Prop) : f (g230 x) = f (g229 x) @[simp] axiom s230 (x : Prop) : f (g231 x) = f (g230 x) @[simp] axiom s231 (x : Prop) : f (g232 x) = f (g231 x) @[simp] axiom s232 (x : Prop) : f (g233 x) = f (g232 x) @[simp] axiom s233 (x : Prop) : f (g234 x) = f (g233 x) @[simp] axiom s234 (x : Prop) : f (g235 x) = f (g234 x) @[simp] axiom s235 (x : Prop) : f (g236 x) = f (g235 x) @[simp] axiom s236 (x : Prop) : f (g237 x) = f (g236 x) @[simp] axiom s237 (x : Prop) : f (g238 x) = f (g237 x) @[simp] axiom s238 (x : Prop) : f (g239 x) = f (g238 x) @[simp] axiom s239 (x : Prop) : f (g240 x) = f (g239 x) @[simp] axiom s240 (x : Prop) : f (g241 x) = f (g240 x) @[simp] axiom s241 (x : Prop) : f (g242 x) = f (g241 x) @[simp] axiom s242 (x : Prop) : f (g243 x) = f (g242 x) @[simp] axiom s243 (x : Prop) : f (g244 x) = f (g243 x) @[simp] axiom s244 (x : Prop) : f (g245 x) = f (g244 x) @[simp] axiom s245 (x : Prop) : f (g246 x) = f (g245 x) @[simp] axiom s246 (x : Prop) : f (g247 x) = f (g246 x) @[simp] axiom s247 (x : Prop) : f (g248 x) = f (g247 x) @[simp] axiom s248 (x : Prop) : f (g249 x) = f (g248 x) @[simp] axiom s249 (x : Prop) : f (g250 x) = f (g249 x) @[simp] axiom s250 (x : Prop) : f (g251 x) = f (g250 x) @[simp] axiom s251 (x : Prop) : f (g252 x) = f (g251 x) @[simp] axiom s252 (x : Prop) : f (g253 x) = f (g252 x) @[simp] axiom s253 (x : Prop) : f (g254 x) = f (g253 x) @[simp] axiom s254 (x : Prop) : f (g255 x) = f (g254 x) @[simp] axiom s255 (x : Prop) : f (g256 x) = f (g255 x) @[simp] axiom s256 (x : Prop) : f (g257 x) = f (g256 x) @[simp] axiom s257 (x : Prop) : f (g258 x) = f (g257 x) @[simp] axiom s258 (x : Prop) : f (g259 x) = f (g258 x) @[simp] axiom s259 (x : Prop) : f (g260 x) = f (g259 x) @[simp] axiom s260 (x : Prop) : f (g261 x) = f (g260 x) @[simp] axiom s261 (x : Prop) : f (g262 x) = f (g261 x) @[simp] axiom s262 (x : Prop) : f (g263 x) = f (g262 x) @[simp] axiom s263 (x : Prop) : f (g264 x) = f (g263 x) @[simp] axiom s264 (x : Prop) : f (g265 x) = f (g264 x) @[simp] axiom s265 (x : Prop) : f (g266 x) = f (g265 x) @[simp] axiom s266 (x : Prop) : f (g267 x) = f (g266 x) @[simp] axiom s267 (x : Prop) : f (g268 x) = f (g267 x) @[simp] axiom s268 (x : Prop) : f (g269 x) = f (g268 x) @[simp] axiom s269 (x : Prop) : f (g270 x) = f (g269 x) @[simp] axiom s270 (x : Prop) : f (g271 x) = f (g270 x) @[simp] axiom s271 (x : Prop) : f (g272 x) = f (g271 x) @[simp] axiom s272 (x : Prop) : f (g273 x) = f (g272 x) @[simp] axiom s273 (x : Prop) : f (g274 x) = f (g273 x) @[simp] axiom s274 (x : Prop) : f (g275 x) = f (g274 x) @[simp] axiom s275 (x : Prop) : f (g276 x) = f (g275 x) @[simp] axiom s276 (x : Prop) : f (g277 x) = f (g276 x) @[simp] axiom s277 (x : Prop) : f (g278 x) = f (g277 x) @[simp] axiom s278 (x : Prop) : f (g279 x) = f (g278 x) @[simp] axiom s279 (x : Prop) : f (g280 x) = f (g279 x) @[simp] axiom s280 (x : Prop) : f (g281 x) = f (g280 x) @[simp] axiom s281 (x : Prop) : f (g282 x) = f (g281 x) @[simp] axiom s282 (x : Prop) : f (g283 x) = f (g282 x) @[simp] axiom s283 (x : Prop) : f (g284 x) = f (g283 x) @[simp] axiom s284 (x : Prop) : f (g285 x) = f (g284 x) @[simp] axiom s285 (x : Prop) : f (g286 x) = f (g285 x) @[simp] axiom s286 (x : Prop) : f (g287 x) = f (g286 x) @[simp] axiom s287 (x : Prop) : f (g288 x) = f (g287 x) @[simp] axiom s288 (x : Prop) : f (g289 x) = f (g288 x) @[simp] axiom s289 (x : Prop) : f (g290 x) = f (g289 x) @[simp] axiom s290 (x : Prop) : f (g291 x) = f (g290 x) @[simp] axiom s291 (x : Prop) : f (g292 x) = f (g291 x) @[simp] axiom s292 (x : Prop) : f (g293 x) = f (g292 x) @[simp] axiom s293 (x : Prop) : f (g294 x) = f (g293 x) @[simp] axiom s294 (x : Prop) : f (g295 x) = f (g294 x) @[simp] axiom s295 (x : Prop) : f (g296 x) = f (g295 x) @[simp] axiom s296 (x : Prop) : f (g297 x) = f (g296 x) @[simp] axiom s297 (x : Prop) : f (g298 x) = f (g297 x) @[simp] axiom s298 (x : Prop) : f (g299 x) = f (g298 x) @[simp] axiom s299 (x : Prop) : f (g300 x) = f (g299 x) @[simp] axiom s300 (x : Prop) : f (g301 x) = f (g300 x) @[simp] axiom s301 (x : Prop) : f (g302 x) = f (g301 x) @[simp] axiom s302 (x : Prop) : f (g303 x) = f (g302 x) @[simp] axiom s303 (x : Prop) : f (g304 x) = f (g303 x) @[simp] axiom s304 (x : Prop) : f (g305 x) = f (g304 x) @[simp] axiom s305 (x : Prop) : f (g306 x) = f (g305 x) @[simp] axiom s306 (x : Prop) : f (g307 x) = f (g306 x) @[simp] axiom s307 (x : Prop) : f (g308 x) = f (g307 x) @[simp] axiom s308 (x : Prop) : f (g309 x) = f (g308 x) @[simp] axiom s309 (x : Prop) : f (g310 x) = f (g309 x) @[simp] axiom s310 (x : Prop) : f (g311 x) = f (g310 x) @[simp] axiom s311 (x : Prop) : f (g312 x) = f (g311 x) @[simp] axiom s312 (x : Prop) : f (g313 x) = f (g312 x) @[simp] axiom s313 (x : Prop) : f (g314 x) = f (g313 x) @[simp] axiom s314 (x : Prop) : f (g315 x) = f (g314 x) @[simp] axiom s315 (x : Prop) : f (g316 x) = f (g315 x) @[simp] axiom s316 (x : Prop) : f (g317 x) = f (g316 x) @[simp] axiom s317 (x : Prop) : f (g318 x) = f (g317 x) @[simp] axiom s318 (x : Prop) : f (g319 x) = f (g318 x) @[simp] axiom s319 (x : Prop) : f (g320 x) = f (g319 x) @[simp] axiom s320 (x : Prop) : f (g321 x) = f (g320 x) @[simp] axiom s321 (x : Prop) : f (g322 x) = f (g321 x) @[simp] axiom s322 (x : Prop) : f (g323 x) = f (g322 x) @[simp] axiom s323 (x : Prop) : f (g324 x) = f (g323 x) @[simp] axiom s324 (x : Prop) : f (g325 x) = f (g324 x) @[simp] axiom s325 (x : Prop) : f (g326 x) = f (g325 x) @[simp] axiom s326 (x : Prop) : f (g327 x) = f (g326 x) @[simp] axiom s327 (x : Prop) : f (g328 x) = f (g327 x) @[simp] axiom s328 (x : Prop) : f (g329 x) = f (g328 x) @[simp] axiom s329 (x : Prop) : f (g330 x) = f (g329 x) @[simp] axiom s330 (x : Prop) : f (g331 x) = f (g330 x) @[simp] axiom s331 (x : Prop) : f (g332 x) = f (g331 x) @[simp] axiom s332 (x : Prop) : f (g333 x) = f (g332 x) @[simp] axiom s333 (x : Prop) : f (g334 x) = f (g333 x) @[simp] axiom s334 (x : Prop) : f (g335 x) = f (g334 x) @[simp] axiom s335 (x : Prop) : f (g336 x) = f (g335 x) @[simp] axiom s336 (x : Prop) : f (g337 x) = f (g336 x) @[simp] axiom s337 (x : Prop) : f (g338 x) = f (g337 x) @[simp] axiom s338 (x : Prop) : f (g339 x) = f (g338 x) @[simp] axiom s339 (x : Prop) : f (g340 x) = f (g339 x) @[simp] axiom s340 (x : Prop) : f (g341 x) = f (g340 x) @[simp] axiom s341 (x : Prop) : f (g342 x) = f (g341 x) @[simp] axiom s342 (x : Prop) : f (g343 x) = f (g342 x) @[simp] axiom s343 (x : Prop) : f (g344 x) = f (g343 x) @[simp] axiom s344 (x : Prop) : f (g345 x) = f (g344 x) @[simp] axiom s345 (x : Prop) : f (g346 x) = f (g345 x) @[simp] axiom s346 (x : Prop) : f (g347 x) = f (g346 x) @[simp] axiom s347 (x : Prop) : f (g348 x) = f (g347 x) @[simp] axiom s348 (x : Prop) : f (g349 x) = f (g348 x) @[simp] axiom s349 (x : Prop) : f (g350 x) = f (g349 x) @[simp] axiom s350 (x : Prop) : f (g351 x) = f (g350 x) @[simp] axiom s351 (x : Prop) : f (g352 x) = f (g351 x) @[simp] axiom s352 (x : Prop) : f (g353 x) = f (g352 x) @[simp] axiom s353 (x : Prop) : f (g354 x) = f (g353 x) @[simp] axiom s354 (x : Prop) : f (g355 x) = f (g354 x) @[simp] axiom s355 (x : Prop) : f (g356 x) = f (g355 x) @[simp] axiom s356 (x : Prop) : f (g357 x) = f (g356 x) @[simp] axiom s357 (x : Prop) : f (g358 x) = f (g357 x) @[simp] axiom s358 (x : Prop) : f (g359 x) = f (g358 x) @[simp] axiom s359 (x : Prop) : f (g360 x) = f (g359 x) @[simp] axiom s360 (x : Prop) : f (g361 x) = f (g360 x) @[simp] axiom s361 (x : Prop) : f (g362 x) = f (g361 x) @[simp] axiom s362 (x : Prop) : f (g363 x) = f (g362 x) @[simp] axiom s363 (x : Prop) : f (g364 x) = f (g363 x) @[simp] axiom s364 (x : Prop) : f (g365 x) = f (g364 x) @[simp] axiom s365 (x : Prop) : f (g366 x) = f (g365 x) @[simp] axiom s366 (x : Prop) : f (g367 x) = f (g366 x) @[simp] axiom s367 (x : Prop) : f (g368 x) = f (g367 x) @[simp] axiom s368 (x : Prop) : f (g369 x) = f (g368 x) @[simp] axiom s369 (x : Prop) : f (g370 x) = f (g369 x) @[simp] axiom s370 (x : Prop) : f (g371 x) = f (g370 x) @[simp] axiom s371 (x : Prop) : f (g372 x) = f (g371 x) @[simp] axiom s372 (x : Prop) : f (g373 x) = f (g372 x) @[simp] axiom s373 (x : Prop) : f (g374 x) = f (g373 x) @[simp] axiom s374 (x : Prop) : f (g375 x) = f (g374 x) @[simp] axiom s375 (x : Prop) : f (g376 x) = f (g375 x) @[simp] axiom s376 (x : Prop) : f (g377 x) = f (g376 x) @[simp] axiom s377 (x : Prop) : f (g378 x) = f (g377 x) @[simp] axiom s378 (x : Prop) : f (g379 x) = f (g378 x) @[simp] axiom s379 (x : Prop) : f (g380 x) = f (g379 x) @[simp] axiom s380 (x : Prop) : f (g381 x) = f (g380 x) @[simp] axiom s381 (x : Prop) : f (g382 x) = f (g381 x) @[simp] axiom s382 (x : Prop) : f (g383 x) = f (g382 x) @[simp] axiom s383 (x : Prop) : f (g384 x) = f (g383 x) @[simp] axiom s384 (x : Prop) : f (g385 x) = f (g384 x) @[simp] axiom s385 (x : Prop) : f (g386 x) = f (g385 x) @[simp] axiom s386 (x : Prop) : f (g387 x) = f (g386 x) @[simp] axiom s387 (x : Prop) : f (g388 x) = f (g387 x) @[simp] axiom s388 (x : Prop) : f (g389 x) = f (g388 x) @[simp] axiom s389 (x : Prop) : f (g390 x) = f (g389 x) @[simp] axiom s390 (x : Prop) : f (g391 x) = f (g390 x) @[simp] axiom s391 (x : Prop) : f (g392 x) = f (g391 x) @[simp] axiom s392 (x : Prop) : f (g393 x) = f (g392 x) @[simp] axiom s393 (x : Prop) : f (g394 x) = f (g393 x) @[simp] axiom s394 (x : Prop) : f (g395 x) = f (g394 x) @[simp] axiom s395 (x : Prop) : f (g396 x) = f (g395 x) @[simp] axiom s396 (x : Prop) : f (g397 x) = f (g396 x) @[simp] axiom s397 (x : Prop) : f (g398 x) = f (g397 x) @[simp] axiom s398 (x : Prop) : f (g399 x) = f (g398 x) @[simp] axiom s399 (x : Prop) : f (g400 x) = f (g399 x) @[simp] axiom s400 (x : Prop) : f (g401 x) = f (g400 x) @[simp] axiom s401 (x : Prop) : f (g402 x) = f (g401 x) @[simp] axiom s402 (x : Prop) : f (g403 x) = f (g402 x) @[simp] axiom s403 (x : Prop) : f (g404 x) = f (g403 x) @[simp] axiom s404 (x : Prop) : f (g405 x) = f (g404 x) @[simp] axiom s405 (x : Prop) : f (g406 x) = f (g405 x) @[simp] axiom s406 (x : Prop) : f (g407 x) = f (g406 x) @[simp] axiom s407 (x : Prop) : f (g408 x) = f (g407 x) @[simp] axiom s408 (x : Prop) : f (g409 x) = f (g408 x) @[simp] axiom s409 (x : Prop) : f (g410 x) = f (g409 x) @[simp] axiom s410 (x : Prop) : f (g411 x) = f (g410 x) @[simp] axiom s411 (x : Prop) : f (g412 x) = f (g411 x) @[simp] axiom s412 (x : Prop) : f (g413 x) = f (g412 x) @[simp] axiom s413 (x : Prop) : f (g414 x) = f (g413 x) @[simp] axiom s414 (x : Prop) : f (g415 x) = f (g414 x) @[simp] axiom s415 (x : Prop) : f (g416 x) = f (g415 x) @[simp] axiom s416 (x : Prop) : f (g417 x) = f (g416 x) @[simp] axiom s417 (x : Prop) : f (g418 x) = f (g417 x) @[simp] axiom s418 (x : Prop) : f (g419 x) = f (g418 x) @[simp] axiom s419 (x : Prop) : f (g420 x) = f (g419 x) @[simp] axiom s420 (x : Prop) : f (g421 x) = f (g420 x) @[simp] axiom s421 (x : Prop) : f (g422 x) = f (g421 x) @[simp] axiom s422 (x : Prop) : f (g423 x) = f (g422 x) @[simp] axiom s423 (x : Prop) : f (g424 x) = f (g423 x) @[simp] axiom s424 (x : Prop) : f (g425 x) = f (g424 x) @[simp] axiom s425 (x : Prop) : f (g426 x) = f (g425 x) @[simp] axiom s426 (x : Prop) : f (g427 x) = f (g426 x) @[simp] axiom s427 (x : Prop) : f (g428 x) = f (g427 x) @[simp] axiom s428 (x : Prop) : f (g429 x) = f (g428 x) @[simp] axiom s429 (x : Prop) : f (g430 x) = f (g429 x) @[simp] axiom s430 (x : Prop) : f (g431 x) = f (g430 x) @[simp] axiom s431 (x : Prop) : f (g432 x) = f (g431 x) @[simp] axiom s432 (x : Prop) : f (g433 x) = f (g432 x) @[simp] axiom s433 (x : Prop) : f (g434 x) = f (g433 x) @[simp] axiom s434 (x : Prop) : f (g435 x) = f (g434 x) @[simp] axiom s435 (x : Prop) : f (g436 x) = f (g435 x) @[simp] axiom s436 (x : Prop) : f (g437 x) = f (g436 x) @[simp] axiom s437 (x : Prop) : f (g438 x) = f (g437 x) @[simp] axiom s438 (x : Prop) : f (g439 x) = f (g438 x) @[simp] axiom s439 (x : Prop) : f (g440 x) = f (g439 x) @[simp] axiom s440 (x : Prop) : f (g441 x) = f (g440 x) @[simp] axiom s441 (x : Prop) : f (g442 x) = f (g441 x) @[simp] axiom s442 (x : Prop) : f (g443 x) = f (g442 x) @[simp] axiom s443 (x : Prop) : f (g444 x) = f (g443 x) @[simp] axiom s444 (x : Prop) : f (g445 x) = f (g444 x) @[simp] axiom s445 (x : Prop) : f (g446 x) = f (g445 x) @[simp] axiom s446 (x : Prop) : f (g447 x) = f (g446 x) @[simp] axiom s447 (x : Prop) : f (g448 x) = f (g447 x) @[simp] axiom s448 (x : Prop) : f (g449 x) = f (g448 x) @[simp] axiom s449 (x : Prop) : f (g450 x) = f (g449 x) @[simp] axiom s450 (x : Prop) : f (g451 x) = f (g450 x) @[simp] axiom s451 (x : Prop) : f (g452 x) = f (g451 x) @[simp] axiom s452 (x : Prop) : f (g453 x) = f (g452 x) @[simp] axiom s453 (x : Prop) : f (g454 x) = f (g453 x) @[simp] axiom s454 (x : Prop) : f (g455 x) = f (g454 x) @[simp] axiom s455 (x : Prop) : f (g456 x) = f (g455 x) @[simp] axiom s456 (x : Prop) : f (g457 x) = f (g456 x) @[simp] axiom s457 (x : Prop) : f (g458 x) = f (g457 x) @[simp] axiom s458 (x : Prop) : f (g459 x) = f (g458 x) @[simp] axiom s459 (x : Prop) : f (g460 x) = f (g459 x) @[simp] axiom s460 (x : Prop) : f (g461 x) = f (g460 x) @[simp] axiom s461 (x : Prop) : f (g462 x) = f (g461 x) @[simp] axiom s462 (x : Prop) : f (g463 x) = f (g462 x) @[simp] axiom s463 (x : Prop) : f (g464 x) = f (g463 x) @[simp] axiom s464 (x : Prop) : f (g465 x) = f (g464 x) @[simp] axiom s465 (x : Prop) : f (g466 x) = f (g465 x) @[simp] axiom s466 (x : Prop) : f (g467 x) = f (g466 x) @[simp] axiom s467 (x : Prop) : f (g468 x) = f (g467 x) @[simp] axiom s468 (x : Prop) : f (g469 x) = f (g468 x) @[simp] axiom s469 (x : Prop) : f (g470 x) = f (g469 x) @[simp] axiom s470 (x : Prop) : f (g471 x) = f (g470 x) @[simp] axiom s471 (x : Prop) : f (g472 x) = f (g471 x) @[simp] axiom s472 (x : Prop) : f (g473 x) = f (g472 x) @[simp] axiom s473 (x : Prop) : f (g474 x) = f (g473 x) @[simp] axiom s474 (x : Prop) : f (g475 x) = f (g474 x) @[simp] axiom s475 (x : Prop) : f (g476 x) = f (g475 x) @[simp] axiom s476 (x : Prop) : f (g477 x) = f (g476 x) @[simp] axiom s477 (x : Prop) : f (g478 x) = f (g477 x) @[simp] axiom s478 (x : Prop) : f (g479 x) = f (g478 x) @[simp] axiom s479 (x : Prop) : f (g480 x) = f (g479 x) @[simp] axiom s480 (x : Prop) : f (g481 x) = f (g480 x) @[simp] axiom s481 (x : Prop) : f (g482 x) = f (g481 x) @[simp] axiom s482 (x : Prop) : f (g483 x) = f (g482 x) @[simp] axiom s483 (x : Prop) : f (g484 x) = f (g483 x) @[simp] axiom s484 (x : Prop) : f (g485 x) = f (g484 x) @[simp] axiom s485 (x : Prop) : f (g486 x) = f (g485 x) @[simp] axiom s486 (x : Prop) : f (g487 x) = f (g486 x) @[simp] axiom s487 (x : Prop) : f (g488 x) = f (g487 x) @[simp] axiom s488 (x : Prop) : f (g489 x) = f (g488 x) @[simp] axiom s489 (x : Prop) : f (g490 x) = f (g489 x) @[simp] axiom s490 (x : Prop) : f (g491 x) = f (g490 x) @[simp] axiom s491 (x : Prop) : f (g492 x) = f (g491 x) @[simp] axiom s492 (x : Prop) : f (g493 x) = f (g492 x) @[simp] axiom s493 (x : Prop) : f (g494 x) = f (g493 x) @[simp] axiom s494 (x : Prop) : f (g495 x) = f (g494 x) @[simp] axiom s495 (x : Prop) : f (g496 x) = f (g495 x) @[simp] axiom s496 (x : Prop) : f (g497 x) = f (g496 x) @[simp] axiom s497 (x : Prop) : f (g498 x) = f (g497 x) @[simp] axiom s498 (x : Prop) : f (g499 x) = f (g498 x) @[simp] axiom s499 (x : Prop) : f (g500 x) = f (g499 x) @[simp] axiom s500 (x : Prop) : f (g501 x) = f (g500 x) @[simp] axiom s501 (x : Prop) : f (g502 x) = f (g501 x) @[simp] axiom s502 (x : Prop) : f (g503 x) = f (g502 x) @[simp] axiom s503 (x : Prop) : f (g504 x) = f (g503 x) @[simp] axiom s504 (x : Prop) : f (g505 x) = f (g504 x) @[simp] axiom s505 (x : Prop) : f (g506 x) = f (g505 x) @[simp] axiom s506 (x : Prop) : f (g507 x) = f (g506 x) @[simp] axiom s507 (x : Prop) : f (g508 x) = f (g507 x) @[simp] axiom s508 (x : Prop) : f (g509 x) = f (g508 x) @[simp] axiom s509 (x : Prop) : f (g510 x) = f (g509 x) @[simp] axiom s510 (x : Prop) : f (g511 x) = f (g510 x) @[simp] axiom s511 (x : Prop) : f (g512 x) = f (g511 x) @[simp] axiom s512 (x : Prop) : f (g513 x) = f (g512 x) @[simp] axiom s513 (x : Prop) : f (g514 x) = f (g513 x) @[simp] axiom s514 (x : Prop) : f (g515 x) = f (g514 x) @[simp] axiom s515 (x : Prop) : f (g516 x) = f (g515 x) @[simp] axiom s516 (x : Prop) : f (g517 x) = f (g516 x) @[simp] axiom s517 (x : Prop) : f (g518 x) = f (g517 x) @[simp] axiom s518 (x : Prop) : f (g519 x) = f (g518 x) @[simp] axiom s519 (x : Prop) : f (g520 x) = f (g519 x) @[simp] axiom s520 (x : Prop) : f (g521 x) = f (g520 x) @[simp] axiom s521 (x : Prop) : f (g522 x) = f (g521 x) @[simp] axiom s522 (x : Prop) : f (g523 x) = f (g522 x) @[simp] axiom s523 (x : Prop) : f (g524 x) = f (g523 x) @[simp] axiom s524 (x : Prop) : f (g525 x) = f (g524 x) @[simp] axiom s525 (x : Prop) : f (g526 x) = f (g525 x) @[simp] axiom s526 (x : Prop) : f (g527 x) = f (g526 x) @[simp] axiom s527 (x : Prop) : f (g528 x) = f (g527 x) @[simp] axiom s528 (x : Prop) : f (g529 x) = f (g528 x) @[simp] axiom s529 (x : Prop) : f (g530 x) = f (g529 x) @[simp] axiom s530 (x : Prop) : f (g531 x) = f (g530 x) @[simp] axiom s531 (x : Prop) : f (g532 x) = f (g531 x) @[simp] axiom s532 (x : Prop) : f (g533 x) = f (g532 x) @[simp] axiom s533 (x : Prop) : f (g534 x) = f (g533 x) @[simp] axiom s534 (x : Prop) : f (g535 x) = f (g534 x) @[simp] axiom s535 (x : Prop) : f (g536 x) = f (g535 x) @[simp] axiom s536 (x : Prop) : f (g537 x) = f (g536 x) @[simp] axiom s537 (x : Prop) : f (g538 x) = f (g537 x) @[simp] axiom s538 (x : Prop) : f (g539 x) = f (g538 x) @[simp] axiom s539 (x : Prop) : f (g540 x) = f (g539 x) @[simp] axiom s540 (x : Prop) : f (g541 x) = f (g540 x) @[simp] axiom s541 (x : Prop) : f (g542 x) = f (g541 x) @[simp] axiom s542 (x : Prop) : f (g543 x) = f (g542 x) @[simp] axiom s543 (x : Prop) : f (g544 x) = f (g543 x) @[simp] axiom s544 (x : Prop) : f (g545 x) = f (g544 x) @[simp] axiom s545 (x : Prop) : f (g546 x) = f (g545 x) @[simp] axiom s546 (x : Prop) : f (g547 x) = f (g546 x) @[simp] axiom s547 (x : Prop) : f (g548 x) = f (g547 x) @[simp] axiom s548 (x : Prop) : f (g549 x) = f (g548 x) @[simp] axiom s549 (x : Prop) : f (g550 x) = f (g549 x) @[simp] axiom s550 (x : Prop) : f (g551 x) = f (g550 x) @[simp] axiom s551 (x : Prop) : f (g552 x) = f (g551 x) @[simp] axiom s552 (x : Prop) : f (g553 x) = f (g552 x) @[simp] axiom s553 (x : Prop) : f (g554 x) = f (g553 x) @[simp] axiom s554 (x : Prop) : f (g555 x) = f (g554 x) @[simp] axiom s555 (x : Prop) : f (g556 x) = f (g555 x) @[simp] axiom s556 (x : Prop) : f (g557 x) = f (g556 x) @[simp] axiom s557 (x : Prop) : f (g558 x) = f (g557 x) @[simp] axiom s558 (x : Prop) : f (g559 x) = f (g558 x) @[simp] axiom s559 (x : Prop) : f (g560 x) = f (g559 x) @[simp] axiom s560 (x : Prop) : f (g561 x) = f (g560 x) @[simp] axiom s561 (x : Prop) : f (g562 x) = f (g561 x) @[simp] axiom s562 (x : Prop) : f (g563 x) = f (g562 x) @[simp] axiom s563 (x : Prop) : f (g564 x) = f (g563 x) @[simp] axiom s564 (x : Prop) : f (g565 x) = f (g564 x) @[simp] axiom s565 (x : Prop) : f (g566 x) = f (g565 x) @[simp] axiom s566 (x : Prop) : f (g567 x) = f (g566 x) @[simp] axiom s567 (x : Prop) : f (g568 x) = f (g567 x) @[simp] axiom s568 (x : Prop) : f (g569 x) = f (g568 x) @[simp] axiom s569 (x : Prop) : f (g570 x) = f (g569 x) @[simp] axiom s570 (x : Prop) : f (g571 x) = f (g570 x) @[simp] axiom s571 (x : Prop) : f (g572 x) = f (g571 x) @[simp] axiom s572 (x : Prop) : f (g573 x) = f (g572 x) @[simp] axiom s573 (x : Prop) : f (g574 x) = f (g573 x) @[simp] axiom s574 (x : Prop) : f (g575 x) = f (g574 x) @[simp] axiom s575 (x : Prop) : f (g576 x) = f (g575 x) @[simp] axiom s576 (x : Prop) : f (g577 x) = f (g576 x) @[simp] axiom s577 (x : Prop) : f (g578 x) = f (g577 x) @[simp] axiom s578 (x : Prop) : f (g579 x) = f (g578 x) @[simp] axiom s579 (x : Prop) : f (g580 x) = f (g579 x) @[simp] axiom s580 (x : Prop) : f (g581 x) = f (g580 x) @[simp] axiom s581 (x : Prop) : f (g582 x) = f (g581 x) @[simp] axiom s582 (x : Prop) : f (g583 x) = f (g582 x) @[simp] axiom s583 (x : Prop) : f (g584 x) = f (g583 x) @[simp] axiom s584 (x : Prop) : f (g585 x) = f (g584 x) @[simp] axiom s585 (x : Prop) : f (g586 x) = f (g585 x) @[simp] axiom s586 (x : Prop) : f (g587 x) = f (g586 x) @[simp] axiom s587 (x : Prop) : f (g588 x) = f (g587 x) @[simp] axiom s588 (x : Prop) : f (g589 x) = f (g588 x) @[simp] axiom s589 (x : Prop) : f (g590 x) = f (g589 x) @[simp] axiom s590 (x : Prop) : f (g591 x) = f (g590 x) @[simp] axiom s591 (x : Prop) : f (g592 x) = f (g591 x) @[simp] axiom s592 (x : Prop) : f (g593 x) = f (g592 x) @[simp] axiom s593 (x : Prop) : f (g594 x) = f (g593 x) @[simp] axiom s594 (x : Prop) : f (g595 x) = f (g594 x) @[simp] axiom s595 (x : Prop) : f (g596 x) = f (g595 x) @[simp] axiom s596 (x : Prop) : f (g597 x) = f (g596 x) @[simp] axiom s597 (x : Prop) : f (g598 x) = f (g597 x) @[simp] axiom s598 (x : Prop) : f (g599 x) = f (g598 x) @[simp] axiom s599 (x : Prop) : f (g600 x) = f (g599 x) @[simp] axiom s600 (x : Prop) : f (g601 x) = f (g600 x) @[simp] axiom s601 (x : Prop) : f (g602 x) = f (g601 x) @[simp] axiom s602 (x : Prop) : f (g603 x) = f (g602 x) @[simp] axiom s603 (x : Prop) : f (g604 x) = f (g603 x) @[simp] axiom s604 (x : Prop) : f (g605 x) = f (g604 x) @[simp] axiom s605 (x : Prop) : f (g606 x) = f (g605 x) @[simp] axiom s606 (x : Prop) : f (g607 x) = f (g606 x) @[simp] axiom s607 (x : Prop) : f (g608 x) = f (g607 x) @[simp] axiom s608 (x : Prop) : f (g609 x) = f (g608 x) @[simp] axiom s609 (x : Prop) : f (g610 x) = f (g609 x) @[simp] axiom s610 (x : Prop) : f (g611 x) = f (g610 x) @[simp] axiom s611 (x : Prop) : f (g612 x) = f (g611 x) @[simp] axiom s612 (x : Prop) : f (g613 x) = f (g612 x) @[simp] axiom s613 (x : Prop) : f (g614 x) = f (g613 x) @[simp] axiom s614 (x : Prop) : f (g615 x) = f (g614 x) @[simp] axiom s615 (x : Prop) : f (g616 x) = f (g615 x) @[simp] axiom s616 (x : Prop) : f (g617 x) = f (g616 x) @[simp] axiom s617 (x : Prop) : f (g618 x) = f (g617 x) @[simp] axiom s618 (x : Prop) : f (g619 x) = f (g618 x) @[simp] axiom s619 (x : Prop) : f (g620 x) = f (g619 x) @[simp] axiom s620 (x : Prop) : f (g621 x) = f (g620 x) @[simp] axiom s621 (x : Prop) : f (g622 x) = f (g621 x) @[simp] axiom s622 (x : Prop) : f (g623 x) = f (g622 x) @[simp] axiom s623 (x : Prop) : f (g624 x) = f (g623 x) @[simp] axiom s624 (x : Prop) : f (g625 x) = f (g624 x) @[simp] axiom s625 (x : Prop) : f (g626 x) = f (g625 x) @[simp] axiom s626 (x : Prop) : f (g627 x) = f (g626 x) @[simp] axiom s627 (x : Prop) : f (g628 x) = f (g627 x) @[simp] axiom s628 (x : Prop) : f (g629 x) = f (g628 x) @[simp] axiom s629 (x : Prop) : f (g630 x) = f (g629 x) @[simp] axiom s630 (x : Prop) : f (g631 x) = f (g630 x) @[simp] axiom s631 (x : Prop) : f (g632 x) = f (g631 x) @[simp] axiom s632 (x : Prop) : f (g633 x) = f (g632 x) @[simp] axiom s633 (x : Prop) : f (g634 x) = f (g633 x) @[simp] axiom s634 (x : Prop) : f (g635 x) = f (g634 x) @[simp] axiom s635 (x : Prop) : f (g636 x) = f (g635 x) @[simp] axiom s636 (x : Prop) : f (g637 x) = f (g636 x) @[simp] axiom s637 (x : Prop) : f (g638 x) = f (g637 x) @[simp] axiom s638 (x : Prop) : f (g639 x) = f (g638 x) @[simp] axiom s639 (x : Prop) : f (g640 x) = f (g639 x) @[simp] axiom s640 (x : Prop) : f (g641 x) = f (g640 x) @[simp] axiom s641 (x : Prop) : f (g642 x) = f (g641 x) @[simp] axiom s642 (x : Prop) : f (g643 x) = f (g642 x) @[simp] axiom s643 (x : Prop) : f (g644 x) = f (g643 x) @[simp] axiom s644 (x : Prop) : f (g645 x) = f (g644 x) @[simp] axiom s645 (x : Prop) : f (g646 x) = f (g645 x) @[simp] axiom s646 (x : Prop) : f (g647 x) = f (g646 x) @[simp] axiom s647 (x : Prop) : f (g648 x) = f (g647 x) @[simp] axiom s648 (x : Prop) : f (g649 x) = f (g648 x) @[simp] axiom s649 (x : Prop) : f (g650 x) = f (g649 x) @[simp] axiom s650 (x : Prop) : f (g651 x) = f (g650 x) @[simp] axiom s651 (x : Prop) : f (g652 x) = f (g651 x) @[simp] axiom s652 (x : Prop) : f (g653 x) = f (g652 x) @[simp] axiom s653 (x : Prop) : f (g654 x) = f (g653 x) @[simp] axiom s654 (x : Prop) : f (g655 x) = f (g654 x) @[simp] axiom s655 (x : Prop) : f (g656 x) = f (g655 x) @[simp] axiom s656 (x : Prop) : f (g657 x) = f (g656 x) @[simp] axiom s657 (x : Prop) : f (g658 x) = f (g657 x) @[simp] axiom s658 (x : Prop) : f (g659 x) = f (g658 x) @[simp] axiom s659 (x : Prop) : f (g660 x) = f (g659 x) @[simp] axiom s660 (x : Prop) : f (g661 x) = f (g660 x) @[simp] axiom s661 (x : Prop) : f (g662 x) = f (g661 x) @[simp] axiom s662 (x : Prop) : f (g663 x) = f (g662 x) @[simp] axiom s663 (x : Prop) : f (g664 x) = f (g663 x) @[simp] axiom s664 (x : Prop) : f (g665 x) = f (g664 x) @[simp] axiom s665 (x : Prop) : f (g666 x) = f (g665 x) @[simp] axiom s666 (x : Prop) : f (g667 x) = f (g666 x) @[simp] axiom s667 (x : Prop) : f (g668 x) = f (g667 x) @[simp] axiom s668 (x : Prop) : f (g669 x) = f (g668 x) @[simp] axiom s669 (x : Prop) : f (g670 x) = f (g669 x) @[simp] axiom s670 (x : Prop) : f (g671 x) = f (g670 x) @[simp] axiom s671 (x : Prop) : f (g672 x) = f (g671 x) @[simp] axiom s672 (x : Prop) : f (g673 x) = f (g672 x) @[simp] axiom s673 (x : Prop) : f (g674 x) = f (g673 x) @[simp] axiom s674 (x : Prop) : f (g675 x) = f (g674 x) @[simp] axiom s675 (x : Prop) : f (g676 x) = f (g675 x) @[simp] axiom s676 (x : Prop) : f (g677 x) = f (g676 x) @[simp] axiom s677 (x : Prop) : f (g678 x) = f (g677 x) @[simp] axiom s678 (x : Prop) : f (g679 x) = f (g678 x) @[simp] axiom s679 (x : Prop) : f (g680 x) = f (g679 x) @[simp] axiom s680 (x : Prop) : f (g681 x) = f (g680 x) @[simp] axiom s681 (x : Prop) : f (g682 x) = f (g681 x) @[simp] axiom s682 (x : Prop) : f (g683 x) = f (g682 x) @[simp] axiom s683 (x : Prop) : f (g684 x) = f (g683 x) @[simp] axiom s684 (x : Prop) : f (g685 x) = f (g684 x) @[simp] axiom s685 (x : Prop) : f (g686 x) = f (g685 x) @[simp] axiom s686 (x : Prop) : f (g687 x) = f (g686 x) @[simp] axiom s687 (x : Prop) : f (g688 x) = f (g687 x) @[simp] axiom s688 (x : Prop) : f (g689 x) = f (g688 x) @[simp] axiom s689 (x : Prop) : f (g690 x) = f (g689 x) @[simp] axiom s690 (x : Prop) : f (g691 x) = f (g690 x) @[simp] axiom s691 (x : Prop) : f (g692 x) = f (g691 x) @[simp] axiom s692 (x : Prop) : f (g693 x) = f (g692 x) @[simp] axiom s693 (x : Prop) : f (g694 x) = f (g693 x) @[simp] axiom s694 (x : Prop) : f (g695 x) = f (g694 x) @[simp] axiom s695 (x : Prop) : f (g696 x) = f (g695 x) @[simp] axiom s696 (x : Prop) : f (g697 x) = f (g696 x) @[simp] axiom s697 (x : Prop) : f (g698 x) = f (g697 x) @[simp] axiom s698 (x : Prop) : f (g699 x) = f (g698 x) @[simp] axiom s699 (x : Prop) : f (g700 x) = f (g699 x) @[simp] axiom s700 (x : Prop) : f (g701 x) = f (g700 x) @[simp] axiom s701 (x : Prop) : f (g702 x) = f (g701 x) @[simp] axiom s702 (x : Prop) : f (g703 x) = f (g702 x) @[simp] axiom s703 (x : Prop) : f (g704 x) = f (g703 x) @[simp] axiom s704 (x : Prop) : f (g705 x) = f (g704 x) @[simp] axiom s705 (x : Prop) : f (g706 x) = f (g705 x) @[simp] axiom s706 (x : Prop) : f (g707 x) = f (g706 x) @[simp] axiom s707 (x : Prop) : f (g708 x) = f (g707 x) @[simp] axiom s708 (x : Prop) : f (g709 x) = f (g708 x) @[simp] axiom s709 (x : Prop) : f (g710 x) = f (g709 x) @[simp] axiom s710 (x : Prop) : f (g711 x) = f (g710 x) @[simp] axiom s711 (x : Prop) : f (g712 x) = f (g711 x) @[simp] axiom s712 (x : Prop) : f (g713 x) = f (g712 x) @[simp] axiom s713 (x : Prop) : f (g714 x) = f (g713 x) @[simp] axiom s714 (x : Prop) : f (g715 x) = f (g714 x) @[simp] axiom s715 (x : Prop) : f (g716 x) = f (g715 x) @[simp] axiom s716 (x : Prop) : f (g717 x) = f (g716 x) @[simp] axiom s717 (x : Prop) : f (g718 x) = f (g717 x) @[simp] axiom s718 (x : Prop) : f (g719 x) = f (g718 x) @[simp] axiom s719 (x : Prop) : f (g720 x) = f (g719 x) @[simp] axiom s720 (x : Prop) : f (g721 x) = f (g720 x) @[simp] axiom s721 (x : Prop) : f (g722 x) = f (g721 x) @[simp] axiom s722 (x : Prop) : f (g723 x) = f (g722 x) @[simp] axiom s723 (x : Prop) : f (g724 x) = f (g723 x) @[simp] axiom s724 (x : Prop) : f (g725 x) = f (g724 x) @[simp] axiom s725 (x : Prop) : f (g726 x) = f (g725 x) @[simp] axiom s726 (x : Prop) : f (g727 x) = f (g726 x) @[simp] axiom s727 (x : Prop) : f (g728 x) = f (g727 x) @[simp] axiom s728 (x : Prop) : f (g729 x) = f (g728 x) @[simp] axiom s729 (x : Prop) : f (g730 x) = f (g729 x) @[simp] axiom s730 (x : Prop) : f (g731 x) = f (g730 x) @[simp] axiom s731 (x : Prop) : f (g732 x) = f (g731 x) @[simp] axiom s732 (x : Prop) : f (g733 x) = f (g732 x) @[simp] axiom s733 (x : Prop) : f (g734 x) = f (g733 x) @[simp] axiom s734 (x : Prop) : f (g735 x) = f (g734 x) @[simp] axiom s735 (x : Prop) : f (g736 x) = f (g735 x) @[simp] axiom s736 (x : Prop) : f (g737 x) = f (g736 x) @[simp] axiom s737 (x : Prop) : f (g738 x) = f (g737 x) @[simp] axiom s738 (x : Prop) : f (g739 x) = f (g738 x) @[simp] axiom s739 (x : Prop) : f (g740 x) = f (g739 x) @[simp] axiom s740 (x : Prop) : f (g741 x) = f (g740 x) @[simp] axiom s741 (x : Prop) : f (g742 x) = f (g741 x) @[simp] axiom s742 (x : Prop) : f (g743 x) = f (g742 x) @[simp] axiom s743 (x : Prop) : f (g744 x) = f (g743 x) @[simp] axiom s744 (x : Prop) : f (g745 x) = f (g744 x) @[simp] axiom s745 (x : Prop) : f (g746 x) = f (g745 x) @[simp] axiom s746 (x : Prop) : f (g747 x) = f (g746 x) @[simp] axiom s747 (x : Prop) : f (g748 x) = f (g747 x) @[simp] axiom s748 (x : Prop) : f (g749 x) = f (g748 x) @[simp] axiom s749 (x : Prop) : f (g750 x) = f (g749 x) @[simp] axiom s750 (x : Prop) : f (g751 x) = f (g750 x) @[simp] axiom s751 (x : Prop) : f (g752 x) = f (g751 x) @[simp] axiom s752 (x : Prop) : f (g753 x) = f (g752 x) @[simp] axiom s753 (x : Prop) : f (g754 x) = f (g753 x) @[simp] axiom s754 (x : Prop) : f (g755 x) = f (g754 x) @[simp] axiom s755 (x : Prop) : f (g756 x) = f (g755 x) @[simp] axiom s756 (x : Prop) : f (g757 x) = f (g756 x) @[simp] axiom s757 (x : Prop) : f (g758 x) = f (g757 x) @[simp] axiom s758 (x : Prop) : f (g759 x) = f (g758 x) @[simp] axiom s759 (x : Prop) : f (g760 x) = f (g759 x) @[simp] axiom s760 (x : Prop) : f (g761 x) = f (g760 x) @[simp] axiom s761 (x : Prop) : f (g762 x) = f (g761 x) @[simp] axiom s762 (x : Prop) : f (g763 x) = f (g762 x) @[simp] axiom s763 (x : Prop) : f (g764 x) = f (g763 x) @[simp] axiom s764 (x : Prop) : f (g765 x) = f (g764 x) @[simp] axiom s765 (x : Prop) : f (g766 x) = f (g765 x) @[simp] axiom s766 (x : Prop) : f (g767 x) = f (g766 x) @[simp] axiom s767 (x : Prop) : f (g768 x) = f (g767 x) @[simp] axiom s768 (x : Prop) : f (g769 x) = f (g768 x) @[simp] axiom s769 (x : Prop) : f (g770 x) = f (g769 x) @[simp] axiom s770 (x : Prop) : f (g771 x) = f (g770 x) @[simp] axiom s771 (x : Prop) : f (g772 x) = f (g771 x) @[simp] axiom s772 (x : Prop) : f (g773 x) = f (g772 x) @[simp] axiom s773 (x : Prop) : f (g774 x) = f (g773 x) @[simp] axiom s774 (x : Prop) : f (g775 x) = f (g774 x) @[simp] axiom s775 (x : Prop) : f (g776 x) = f (g775 x) @[simp] axiom s776 (x : Prop) : f (g777 x) = f (g776 x) @[simp] axiom s777 (x : Prop) : f (g778 x) = f (g777 x) @[simp] axiom s778 (x : Prop) : f (g779 x) = f (g778 x) @[simp] axiom s779 (x : Prop) : f (g780 x) = f (g779 x) @[simp] axiom s780 (x : Prop) : f (g781 x) = f (g780 x) @[simp] axiom s781 (x : Prop) : f (g782 x) = f (g781 x) @[simp] axiom s782 (x : Prop) : f (g783 x) = f (g782 x) @[simp] axiom s783 (x : Prop) : f (g784 x) = f (g783 x) @[simp] axiom s784 (x : Prop) : f (g785 x) = f (g784 x) @[simp] axiom s785 (x : Prop) : f (g786 x) = f (g785 x) @[simp] axiom s786 (x : Prop) : f (g787 x) = f (g786 x) @[simp] axiom s787 (x : Prop) : f (g788 x) = f (g787 x) @[simp] axiom s788 (x : Prop) : f (g789 x) = f (g788 x) @[simp] axiom s789 (x : Prop) : f (g790 x) = f (g789 x) @[simp] axiom s790 (x : Prop) : f (g791 x) = f (g790 x) @[simp] axiom s791 (x : Prop) : f (g792 x) = f (g791 x) @[simp] axiom s792 (x : Prop) : f (g793 x) = f (g792 x) @[simp] axiom s793 (x : Prop) : f (g794 x) = f (g793 x) @[simp] axiom s794 (x : Prop) : f (g795 x) = f (g794 x) @[simp] axiom s795 (x : Prop) : f (g796 x) = f (g795 x) @[simp] axiom s796 (x : Prop) : f (g797 x) = f (g796 x) @[simp] axiom s797 (x : Prop) : f (g798 x) = f (g797 x) @[simp] axiom s798 (x : Prop) : f (g799 x) = f (g798 x) @[simp] axiom s799 (x : Prop) : f (g800 x) = f (g799 x) @[simp] axiom s800 (x : Prop) : f (g801 x) = f (g800 x) @[simp] axiom s801 (x : Prop) : f (g802 x) = f (g801 x) @[simp] axiom s802 (x : Prop) : f (g803 x) = f (g802 x) @[simp] axiom s803 (x : Prop) : f (g804 x) = f (g803 x) @[simp] axiom s804 (x : Prop) : f (g805 x) = f (g804 x) @[simp] axiom s805 (x : Prop) : f (g806 x) = f (g805 x) @[simp] axiom s806 (x : Prop) : f (g807 x) = f (g806 x) @[simp] axiom s807 (x : Prop) : f (g808 x) = f (g807 x) @[simp] axiom s808 (x : Prop) : f (g809 x) = f (g808 x) @[simp] axiom s809 (x : Prop) : f (g810 x) = f (g809 x) @[simp] axiom s810 (x : Prop) : f (g811 x) = f (g810 x) @[simp] axiom s811 (x : Prop) : f (g812 x) = f (g811 x) @[simp] axiom s812 (x : Prop) : f (g813 x) = f (g812 x) @[simp] axiom s813 (x : Prop) : f (g814 x) = f (g813 x) @[simp] axiom s814 (x : Prop) : f (g815 x) = f (g814 x) @[simp] axiom s815 (x : Prop) : f (g816 x) = f (g815 x) @[simp] axiom s816 (x : Prop) : f (g817 x) = f (g816 x) @[simp] axiom s817 (x : Prop) : f (g818 x) = f (g817 x) @[simp] axiom s818 (x : Prop) : f (g819 x) = f (g818 x) @[simp] axiom s819 (x : Prop) : f (g820 x) = f (g819 x) @[simp] axiom s820 (x : Prop) : f (g821 x) = f (g820 x) @[simp] axiom s821 (x : Prop) : f (g822 x) = f (g821 x) @[simp] axiom s822 (x : Prop) : f (g823 x) = f (g822 x) @[simp] axiom s823 (x : Prop) : f (g824 x) = f (g823 x) @[simp] axiom s824 (x : Prop) : f (g825 x) = f (g824 x) @[simp] axiom s825 (x : Prop) : f (g826 x) = f (g825 x) @[simp] axiom s826 (x : Prop) : f (g827 x) = f (g826 x) @[simp] axiom s827 (x : Prop) : f (g828 x) = f (g827 x) @[simp] axiom s828 (x : Prop) : f (g829 x) = f (g828 x) @[simp] axiom s829 (x : Prop) : f (g830 x) = f (g829 x) @[simp] axiom s830 (x : Prop) : f (g831 x) = f (g830 x) @[simp] axiom s831 (x : Prop) : f (g832 x) = f (g831 x) @[simp] axiom s832 (x : Prop) : f (g833 x) = f (g832 x) @[simp] axiom s833 (x : Prop) : f (g834 x) = f (g833 x) @[simp] axiom s834 (x : Prop) : f (g835 x) = f (g834 x) @[simp] axiom s835 (x : Prop) : f (g836 x) = f (g835 x) @[simp] axiom s836 (x : Prop) : f (g837 x) = f (g836 x) @[simp] axiom s837 (x : Prop) : f (g838 x) = f (g837 x) @[simp] axiom s838 (x : Prop) : f (g839 x) = f (g838 x) @[simp] axiom s839 (x : Prop) : f (g840 x) = f (g839 x) @[simp] axiom s840 (x : Prop) : f (g841 x) = f (g840 x) @[simp] axiom s841 (x : Prop) : f (g842 x) = f (g841 x) @[simp] axiom s842 (x : Prop) : f (g843 x) = f (g842 x) @[simp] axiom s843 (x : Prop) : f (g844 x) = f (g843 x) @[simp] axiom s844 (x : Prop) : f (g845 x) = f (g844 x) @[simp] axiom s845 (x : Prop) : f (g846 x) = f (g845 x) @[simp] axiom s846 (x : Prop) : f (g847 x) = f (g846 x) @[simp] axiom s847 (x : Prop) : f (g848 x) = f (g847 x) @[simp] axiom s848 (x : Prop) : f (g849 x) = f (g848 x) @[simp] axiom s849 (x : Prop) : f (g850 x) = f (g849 x) @[simp] axiom s850 (x : Prop) : f (g851 x) = f (g850 x) @[simp] axiom s851 (x : Prop) : f (g852 x) = f (g851 x) @[simp] axiom s852 (x : Prop) : f (g853 x) = f (g852 x) @[simp] axiom s853 (x : Prop) : f (g854 x) = f (g853 x) @[simp] axiom s854 (x : Prop) : f (g855 x) = f (g854 x) @[simp] axiom s855 (x : Prop) : f (g856 x) = f (g855 x) @[simp] axiom s856 (x : Prop) : f (g857 x) = f (g856 x) @[simp] axiom s857 (x : Prop) : f (g858 x) = f (g857 x) @[simp] axiom s858 (x : Prop) : f (g859 x) = f (g858 x) @[simp] axiom s859 (x : Prop) : f (g860 x) = f (g859 x) @[simp] axiom s860 (x : Prop) : f (g861 x) = f (g860 x) @[simp] axiom s861 (x : Prop) : f (g862 x) = f (g861 x) @[simp] axiom s862 (x : Prop) : f (g863 x) = f (g862 x) @[simp] axiom s863 (x : Prop) : f (g864 x) = f (g863 x) @[simp] axiom s864 (x : Prop) : f (g865 x) = f (g864 x) @[simp] axiom s865 (x : Prop) : f (g866 x) = f (g865 x) @[simp] axiom s866 (x : Prop) : f (g867 x) = f (g866 x) @[simp] axiom s867 (x : Prop) : f (g868 x) = f (g867 x) @[simp] axiom s868 (x : Prop) : f (g869 x) = f (g868 x) @[simp] axiom s869 (x : Prop) : f (g870 x) = f (g869 x) @[simp] axiom s870 (x : Prop) : f (g871 x) = f (g870 x) @[simp] axiom s871 (x : Prop) : f (g872 x) = f (g871 x) @[simp] axiom s872 (x : Prop) : f (g873 x) = f (g872 x) @[simp] axiom s873 (x : Prop) : f (g874 x) = f (g873 x) @[simp] axiom s874 (x : Prop) : f (g875 x) = f (g874 x) @[simp] axiom s875 (x : Prop) : f (g876 x) = f (g875 x) @[simp] axiom s876 (x : Prop) : f (g877 x) = f (g876 x) @[simp] axiom s877 (x : Prop) : f (g878 x) = f (g877 x) @[simp] axiom s878 (x : Prop) : f (g879 x) = f (g878 x) @[simp] axiom s879 (x : Prop) : f (g880 x) = f (g879 x) @[simp] axiom s880 (x : Prop) : f (g881 x) = f (g880 x) @[simp] axiom s881 (x : Prop) : f (g882 x) = f (g881 x) @[simp] axiom s882 (x : Prop) : f (g883 x) = f (g882 x) @[simp] axiom s883 (x : Prop) : f (g884 x) = f (g883 x) @[simp] axiom s884 (x : Prop) : f (g885 x) = f (g884 x) @[simp] axiom s885 (x : Prop) : f (g886 x) = f (g885 x) @[simp] axiom s886 (x : Prop) : f (g887 x) = f (g886 x) @[simp] axiom s887 (x : Prop) : f (g888 x) = f (g887 x) @[simp] axiom s888 (x : Prop) : f (g889 x) = f (g888 x) @[simp] axiom s889 (x : Prop) : f (g890 x) = f (g889 x) @[simp] axiom s890 (x : Prop) : f (g891 x) = f (g890 x) @[simp] axiom s891 (x : Prop) : f (g892 x) = f (g891 x) @[simp] axiom s892 (x : Prop) : f (g893 x) = f (g892 x) @[simp] axiom s893 (x : Prop) : f (g894 x) = f (g893 x) @[simp] axiom s894 (x : Prop) : f (g895 x) = f (g894 x) @[simp] axiom s895 (x : Prop) : f (g896 x) = f (g895 x) @[simp] axiom s896 (x : Prop) : f (g897 x) = f (g896 x) @[simp] axiom s897 (x : Prop) : f (g898 x) = f (g897 x) @[simp] axiom s898 (x : Prop) : f (g899 x) = f (g898 x) @[simp] axiom s899 (x : Prop) : f (g900 x) = f (g899 x) @[simp] axiom s900 (x : Prop) : f (g901 x) = f (g900 x) @[simp] axiom s901 (x : Prop) : f (g902 x) = f (g901 x) @[simp] axiom s902 (x : Prop) : f (g903 x) = f (g902 x) @[simp] axiom s903 (x : Prop) : f (g904 x) = f (g903 x) @[simp] axiom s904 (x : Prop) : f (g905 x) = f (g904 x) @[simp] axiom s905 (x : Prop) : f (g906 x) = f (g905 x) @[simp] axiom s906 (x : Prop) : f (g907 x) = f (g906 x) @[simp] axiom s907 (x : Prop) : f (g908 x) = f (g907 x) @[simp] axiom s908 (x : Prop) : f (g909 x) = f (g908 x) @[simp] axiom s909 (x : Prop) : f (g910 x) = f (g909 x) @[simp] axiom s910 (x : Prop) : f (g911 x) = f (g910 x) @[simp] axiom s911 (x : Prop) : f (g912 x) = f (g911 x) @[simp] axiom s912 (x : Prop) : f (g913 x) = f (g912 x) @[simp] axiom s913 (x : Prop) : f (g914 x) = f (g913 x) @[simp] axiom s914 (x : Prop) : f (g915 x) = f (g914 x) @[simp] axiom s915 (x : Prop) : f (g916 x) = f (g915 x) @[simp] axiom s916 (x : Prop) : f (g917 x) = f (g916 x) @[simp] axiom s917 (x : Prop) : f (g918 x) = f (g917 x) @[simp] axiom s918 (x : Prop) : f (g919 x) = f (g918 x) @[simp] axiom s919 (x : Prop) : f (g920 x) = f (g919 x) @[simp] axiom s920 (x : Prop) : f (g921 x) = f (g920 x) @[simp] axiom s921 (x : Prop) : f (g922 x) = f (g921 x) @[simp] axiom s922 (x : Prop) : f (g923 x) = f (g922 x) @[simp] axiom s923 (x : Prop) : f (g924 x) = f (g923 x) @[simp] axiom s924 (x : Prop) : f (g925 x) = f (g924 x) @[simp] axiom s925 (x : Prop) : f (g926 x) = f (g925 x) @[simp] axiom s926 (x : Prop) : f (g927 x) = f (g926 x) @[simp] axiom s927 (x : Prop) : f (g928 x) = f (g927 x) @[simp] axiom s928 (x : Prop) : f (g929 x) = f (g928 x) @[simp] axiom s929 (x : Prop) : f (g930 x) = f (g929 x) @[simp] axiom s930 (x : Prop) : f (g931 x) = f (g930 x) @[simp] axiom s931 (x : Prop) : f (g932 x) = f (g931 x) @[simp] axiom s932 (x : Prop) : f (g933 x) = f (g932 x) @[simp] axiom s933 (x : Prop) : f (g934 x) = f (g933 x) @[simp] axiom s934 (x : Prop) : f (g935 x) = f (g934 x) @[simp] axiom s935 (x : Prop) : f (g936 x) = f (g935 x) @[simp] axiom s936 (x : Prop) : f (g937 x) = f (g936 x) @[simp] axiom s937 (x : Prop) : f (g938 x) = f (g937 x) @[simp] axiom s938 (x : Prop) : f (g939 x) = f (g938 x) @[simp] axiom s939 (x : Prop) : f (g940 x) = f (g939 x) @[simp] axiom s940 (x : Prop) : f (g941 x) = f (g940 x) @[simp] axiom s941 (x : Prop) : f (g942 x) = f (g941 x) @[simp] axiom s942 (x : Prop) : f (g943 x) = f (g942 x) @[simp] axiom s943 (x : Prop) : f (g944 x) = f (g943 x) @[simp] axiom s944 (x : Prop) : f (g945 x) = f (g944 x) @[simp] axiom s945 (x : Prop) : f (g946 x) = f (g945 x) @[simp] axiom s946 (x : Prop) : f (g947 x) = f (g946 x) @[simp] axiom s947 (x : Prop) : f (g948 x) = f (g947 x) @[simp] axiom s948 (x : Prop) : f (g949 x) = f (g948 x) @[simp] axiom s949 (x : Prop) : f (g950 x) = f (g949 x) @[simp] axiom s950 (x : Prop) : f (g951 x) = f (g950 x) @[simp] axiom s951 (x : Prop) : f (g952 x) = f (g951 x) @[simp] axiom s952 (x : Prop) : f (g953 x) = f (g952 x) @[simp] axiom s953 (x : Prop) : f (g954 x) = f (g953 x) @[simp] axiom s954 (x : Prop) : f (g955 x) = f (g954 x) @[simp] axiom s955 (x : Prop) : f (g956 x) = f (g955 x) @[simp] axiom s956 (x : Prop) : f (g957 x) = f (g956 x) @[simp] axiom s957 (x : Prop) : f (g958 x) = f (g957 x) @[simp] axiom s958 (x : Prop) : f (g959 x) = f (g958 x) @[simp] axiom s959 (x : Prop) : f (g960 x) = f (g959 x) @[simp] axiom s960 (x : Prop) : f (g961 x) = f (g960 x) @[simp] axiom s961 (x : Prop) : f (g962 x) = f (g961 x) @[simp] axiom s962 (x : Prop) : f (g963 x) = f (g962 x) @[simp] axiom s963 (x : Prop) : f (g964 x) = f (g963 x) @[simp] axiom s964 (x : Prop) : f (g965 x) = f (g964 x) @[simp] axiom s965 (x : Prop) : f (g966 x) = f (g965 x) @[simp] axiom s966 (x : Prop) : f (g967 x) = f (g966 x) @[simp] axiom s967 (x : Prop) : f (g968 x) = f (g967 x) @[simp] axiom s968 (x : Prop) : f (g969 x) = f (g968 x) @[simp] axiom s969 (x : Prop) : f (g970 x) = f (g969 x) @[simp] axiom s970 (x : Prop) : f (g971 x) = f (g970 x) @[simp] axiom s971 (x : Prop) : f (g972 x) = f (g971 x) @[simp] axiom s972 (x : Prop) : f (g973 x) = f (g972 x) @[simp] axiom s973 (x : Prop) : f (g974 x) = f (g973 x) @[simp] axiom s974 (x : Prop) : f (g975 x) = f (g974 x) @[simp] axiom s975 (x : Prop) : f (g976 x) = f (g975 x) @[simp] axiom s976 (x : Prop) : f (g977 x) = f (g976 x) @[simp] axiom s977 (x : Prop) : f (g978 x) = f (g977 x) @[simp] axiom s978 (x : Prop) : f (g979 x) = f (g978 x) @[simp] axiom s979 (x : Prop) : f (g980 x) = f (g979 x) @[simp] axiom s980 (x : Prop) : f (g981 x) = f (g980 x) @[simp] axiom s981 (x : Prop) : f (g982 x) = f (g981 x) @[simp] axiom s982 (x : Prop) : f (g983 x) = f (g982 x) @[simp] axiom s983 (x : Prop) : f (g984 x) = f (g983 x) @[simp] axiom s984 (x : Prop) : f (g985 x) = f (g984 x) @[simp] axiom s985 (x : Prop) : f (g986 x) = f (g985 x) @[simp] axiom s986 (x : Prop) : f (g987 x) = f (g986 x) @[simp] axiom s987 (x : Prop) : f (g988 x) = f (g987 x) @[simp] axiom s988 (x : Prop) : f (g989 x) = f (g988 x) @[simp] axiom s989 (x : Prop) : f (g990 x) = f (g989 x) @[simp] axiom s990 (x : Prop) : f (g991 x) = f (g990 x) @[simp] axiom s991 (x : Prop) : f (g992 x) = f (g991 x) @[simp] axiom s992 (x : Prop) : f (g993 x) = f (g992 x) @[simp] axiom s993 (x : Prop) : f (g994 x) = f (g993 x) @[simp] axiom s994 (x : Prop) : f (g995 x) = f (g994 x) @[simp] axiom s995 (x : Prop) : f (g996 x) = f (g995 x) @[simp] axiom s996 (x : Prop) : f (g997 x) = f (g996 x) @[simp] axiom s997 (x : Prop) : f (g998 x) = f (g997 x) @[simp] axiom s998 (x : Prop) : f (g999 x) = f (g998 x) @[simp] axiom s999 (x : Prop) : f (g1000 x) = f (g999 x) @[simp] axiom s1000 (x : Prop) : f (g1001 x) = f (g1000 x) @[simp] axiom s1001 (x : Prop) : f (g1002 x) = f (g1001 x) @[simp] axiom s1002 (x : Prop) : f (g1003 x) = f (g1002 x) @[simp] axiom s1003 (x : Prop) : f (g1004 x) = f (g1003 x) @[simp] axiom s1004 (x : Prop) : f (g1005 x) = f (g1004 x) @[simp] axiom s1005 (x : Prop) : f (g1006 x) = f (g1005 x) @[simp] axiom s1006 (x : Prop) : f (g1007 x) = f (g1006 x) @[simp] axiom s1007 (x : Prop) : f (g1008 x) = f (g1007 x) @[simp] axiom s1008 (x : Prop) : f (g1009 x) = f (g1008 x) @[simp] axiom s1009 (x : Prop) : f (g1010 x) = f (g1009 x) @[simp] axiom s1010 (x : Prop) : f (g1011 x) = f (g1010 x) @[simp] axiom s1011 (x : Prop) : f (g1012 x) = f (g1011 x) @[simp] axiom s1012 (x : Prop) : f (g1013 x) = f (g1012 x) @[simp] axiom s1013 (x : Prop) : f (g1014 x) = f (g1013 x) @[simp] axiom s1014 (x : Prop) : f (g1015 x) = f (g1014 x) @[simp] axiom s1015 (x : Prop) : f (g1016 x) = f (g1015 x) @[simp] axiom s1016 (x : Prop) : f (g1017 x) = f (g1016 x) @[simp] axiom s1017 (x : Prop) : f (g1018 x) = f (g1017 x) @[simp] axiom s1018 (x : Prop) : f (g1019 x) = f (g1018 x) @[simp] axiom s1019 (x : Prop) : f (g1020 x) = f (g1019 x) @[simp] axiom s1020 (x : Prop) : f (g1021 x) = f (g1020 x) @[simp] axiom s1021 (x : Prop) : f (g1022 x) = f (g1021 x) @[simp] axiom s1022 (x : Prop) : f (g1023 x) = f (g1022 x) @[simp] axiom s1023 (x : Prop) : f (g1024 x) = f (g1023 x) @[simp] axiom s1024 (x : Prop) : f (g1025 x) = f (g1024 x) @[simp] axiom s1025 (x : Prop) : f (g1026 x) = f (g1025 x) @[simp] axiom s1026 (x : Prop) : f (g1027 x) = f (g1026 x) @[simp] axiom s1027 (x : Prop) : f (g1028 x) = f (g1027 x) @[simp] axiom s1028 (x : Prop) : f (g1029 x) = f (g1028 x) @[simp] axiom s1029 (x : Prop) : f (g1030 x) = f (g1029 x) @[simp] axiom s1030 (x : Prop) : f (g1031 x) = f (g1030 x) @[simp] axiom s1031 (x : Prop) : f (g1032 x) = f (g1031 x) @[simp] axiom s1032 (x : Prop) : f (g1033 x) = f (g1032 x) @[simp] axiom s1033 (x : Prop) : f (g1034 x) = f (g1033 x) @[simp] axiom s1034 (x : Prop) : f (g1035 x) = f (g1034 x) @[simp] axiom s1035 (x : Prop) : f (g1036 x) = f (g1035 x) @[simp] axiom s1036 (x : Prop) : f (g1037 x) = f (g1036 x) @[simp] axiom s1037 (x : Prop) : f (g1038 x) = f (g1037 x) @[simp] axiom s1038 (x : Prop) : f (g1039 x) = f (g1038 x) @[simp] axiom s1039 (x : Prop) : f (g1040 x) = f (g1039 x) @[simp] axiom s1040 (x : Prop) : f (g1041 x) = f (g1040 x) @[simp] axiom s1041 (x : Prop) : f (g1042 x) = f (g1041 x) @[simp] axiom s1042 (x : Prop) : f (g1043 x) = f (g1042 x) @[simp] axiom s1043 (x : Prop) : f (g1044 x) = f (g1043 x) @[simp] axiom s1044 (x : Prop) : f (g1045 x) = f (g1044 x) @[simp] axiom s1045 (x : Prop) : f (g1046 x) = f (g1045 x) @[simp] axiom s1046 (x : Prop) : f (g1047 x) = f (g1046 x) @[simp] axiom s1047 (x : Prop) : f (g1048 x) = f (g1047 x) @[simp] axiom s1048 (x : Prop) : f (g1049 x) = f (g1048 x) @[simp] axiom s1049 (x : Prop) : f (g1050 x) = f (g1049 x) @[simp] axiom s1050 (x : Prop) : f (g1051 x) = f (g1050 x) @[simp] axiom s1051 (x : Prop) : f (g1052 x) = f (g1051 x) @[simp] axiom s1052 (x : Prop) : f (g1053 x) = f (g1052 x) @[simp] axiom s1053 (x : Prop) : f (g1054 x) = f (g1053 x) @[simp] axiom s1054 (x : Prop) : f (g1055 x) = f (g1054 x) @[simp] axiom s1055 (x : Prop) : f (g1056 x) = f (g1055 x) @[simp] axiom s1056 (x : Prop) : f (g1057 x) = f (g1056 x) @[simp] axiom s1057 (x : Prop) : f (g1058 x) = f (g1057 x) @[simp] axiom s1058 (x : Prop) : f (g1059 x) = f (g1058 x) @[simp] axiom s1059 (x : Prop) : f (g1060 x) = f (g1059 x) @[simp] axiom s1060 (x : Prop) : f (g1061 x) = f (g1060 x) @[simp] axiom s1061 (x : Prop) : f (g1062 x) = f (g1061 x) @[simp] axiom s1062 (x : Prop) : f (g1063 x) = f (g1062 x) @[simp] axiom s1063 (x : Prop) : f (g1064 x) = f (g1063 x) @[simp] axiom s1064 (x : Prop) : f (g1065 x) = f (g1064 x) @[simp] axiom s1065 (x : Prop) : f (g1066 x) = f (g1065 x) @[simp] axiom s1066 (x : Prop) : f (g1067 x) = f (g1066 x) @[simp] axiom s1067 (x : Prop) : f (g1068 x) = f (g1067 x) @[simp] axiom s1068 (x : Prop) : f (g1069 x) = f (g1068 x) @[simp] axiom s1069 (x : Prop) : f (g1070 x) = f (g1069 x) @[simp] axiom s1070 (x : Prop) : f (g1071 x) = f (g1070 x) @[simp] axiom s1071 (x : Prop) : f (g1072 x) = f (g1071 x) @[simp] axiom s1072 (x : Prop) : f (g1073 x) = f (g1072 x) @[simp] axiom s1073 (x : Prop) : f (g1074 x) = f (g1073 x) @[simp] axiom s1074 (x : Prop) : f (g1075 x) = f (g1074 x) @[simp] axiom s1075 (x : Prop) : f (g1076 x) = f (g1075 x) @[simp] axiom s1076 (x : Prop) : f (g1077 x) = f (g1076 x) @[simp] axiom s1077 (x : Prop) : f (g1078 x) = f (g1077 x) @[simp] axiom s1078 (x : Prop) : f (g1079 x) = f (g1078 x) @[simp] axiom s1079 (x : Prop) : f (g1080 x) = f (g1079 x) @[simp] axiom s1080 (x : Prop) : f (g1081 x) = f (g1080 x) @[simp] axiom s1081 (x : Prop) : f (g1082 x) = f (g1081 x) @[simp] axiom s1082 (x : Prop) : f (g1083 x) = f (g1082 x) @[simp] axiom s1083 (x : Prop) : f (g1084 x) = f (g1083 x) @[simp] axiom s1084 (x : Prop) : f (g1085 x) = f (g1084 x) @[simp] axiom s1085 (x : Prop) : f (g1086 x) = f (g1085 x) @[simp] axiom s1086 (x : Prop) : f (g1087 x) = f (g1086 x) @[simp] axiom s1087 (x : Prop) : f (g1088 x) = f (g1087 x) @[simp] axiom s1088 (x : Prop) : f (g1089 x) = f (g1088 x) @[simp] axiom s1089 (x : Prop) : f (g1090 x) = f (g1089 x) @[simp] axiom s1090 (x : Prop) : f (g1091 x) = f (g1090 x) @[simp] axiom s1091 (x : Prop) : f (g1092 x) = f (g1091 x) @[simp] axiom s1092 (x : Prop) : f (g1093 x) = f (g1092 x) @[simp] axiom s1093 (x : Prop) : f (g1094 x) = f (g1093 x) @[simp] axiom s1094 (x : Prop) : f (g1095 x) = f (g1094 x) @[simp] axiom s1095 (x : Prop) : f (g1096 x) = f (g1095 x) @[simp] axiom s1096 (x : Prop) : f (g1097 x) = f (g1096 x) @[simp] axiom s1097 (x : Prop) : f (g1098 x) = f (g1097 x) @[simp] axiom s1098 (x : Prop) : f (g1099 x) = f (g1098 x) @[simp] axiom s1099 (x : Prop) : f (g1100 x) = f (g1099 x) @[simp] axiom s1100 (x : Prop) : f (g1101 x) = f (g1100 x) @[simp] axiom s1101 (x : Prop) : f (g1102 x) = f (g1101 x) @[simp] axiom s1102 (x : Prop) : f (g1103 x) = f (g1102 x) @[simp] axiom s1103 (x : Prop) : f (g1104 x) = f (g1103 x) @[simp] axiom s1104 (x : Prop) : f (g1105 x) = f (g1104 x) @[simp] axiom s1105 (x : Prop) : f (g1106 x) = f (g1105 x) @[simp] axiom s1106 (x : Prop) : f (g1107 x) = f (g1106 x) @[simp] axiom s1107 (x : Prop) : f (g1108 x) = f (g1107 x) @[simp] axiom s1108 (x : Prop) : f (g1109 x) = f (g1108 x) @[simp] axiom s1109 (x : Prop) : f (g1110 x) = f (g1109 x) @[simp] axiom s1110 (x : Prop) : f (g1111 x) = f (g1110 x) @[simp] axiom s1111 (x : Prop) : f (g1112 x) = f (g1111 x) @[simp] axiom s1112 (x : Prop) : f (g1113 x) = f (g1112 x) @[simp] axiom s1113 (x : Prop) : f (g1114 x) = f (g1113 x) @[simp] axiom s1114 (x : Prop) : f (g1115 x) = f (g1114 x) @[simp] axiom s1115 (x : Prop) : f (g1116 x) = f (g1115 x) @[simp] axiom s1116 (x : Prop) : f (g1117 x) = f (g1116 x) @[simp] axiom s1117 (x : Prop) : f (g1118 x) = f (g1117 x) @[simp] axiom s1118 (x : Prop) : f (g1119 x) = f (g1118 x) @[simp] axiom s1119 (x : Prop) : f (g1120 x) = f (g1119 x) @[simp] axiom s1120 (x : Prop) : f (g1121 x) = f (g1120 x) @[simp] axiom s1121 (x : Prop) : f (g1122 x) = f (g1121 x) @[simp] axiom s1122 (x : Prop) : f (g1123 x) = f (g1122 x) @[simp] axiom s1123 (x : Prop) : f (g1124 x) = f (g1123 x) @[simp] axiom s1124 (x : Prop) : f (g1125 x) = f (g1124 x) @[simp] axiom s1125 (x : Prop) : f (g1126 x) = f (g1125 x) @[simp] axiom s1126 (x : Prop) : f (g1127 x) = f (g1126 x) @[simp] axiom s1127 (x : Prop) : f (g1128 x) = f (g1127 x) @[simp] axiom s1128 (x : Prop) : f (g1129 x) = f (g1128 x) @[simp] axiom s1129 (x : Prop) : f (g1130 x) = f (g1129 x) @[simp] axiom s1130 (x : Prop) : f (g1131 x) = f (g1130 x) @[simp] axiom s1131 (x : Prop) : f (g1132 x) = f (g1131 x) @[simp] axiom s1132 (x : Prop) : f (g1133 x) = f (g1132 x) @[simp] axiom s1133 (x : Prop) : f (g1134 x) = f (g1133 x) @[simp] axiom s1134 (x : Prop) : f (g1135 x) = f (g1134 x) @[simp] axiom s1135 (x : Prop) : f (g1136 x) = f (g1135 x) @[simp] axiom s1136 (x : Prop) : f (g1137 x) = f (g1136 x) @[simp] axiom s1137 (x : Prop) : f (g1138 x) = f (g1137 x) @[simp] axiom s1138 (x : Prop) : f (g1139 x) = f (g1138 x) @[simp] axiom s1139 (x : Prop) : f (g1140 x) = f (g1139 x) @[simp] axiom s1140 (x : Prop) : f (g1141 x) = f (g1140 x) @[simp] axiom s1141 (x : Prop) : f (g1142 x) = f (g1141 x) @[simp] axiom s1142 (x : Prop) : f (g1143 x) = f (g1142 x) @[simp] axiom s1143 (x : Prop) : f (g1144 x) = f (g1143 x) @[simp] axiom s1144 (x : Prop) : f (g1145 x) = f (g1144 x) @[simp] axiom s1145 (x : Prop) : f (g1146 x) = f (g1145 x) @[simp] axiom s1146 (x : Prop) : f (g1147 x) = f (g1146 x) @[simp] axiom s1147 (x : Prop) : f (g1148 x) = f (g1147 x) @[simp] axiom s1148 (x : Prop) : f (g1149 x) = f (g1148 x) @[simp] axiom s1149 (x : Prop) : f (g1150 x) = f (g1149 x) @[simp] axiom s1150 (x : Prop) : f (g1151 x) = f (g1150 x) @[simp] axiom s1151 (x : Prop) : f (g1152 x) = f (g1151 x) @[simp] axiom s1152 (x : Prop) : f (g1153 x) = f (g1152 x) @[simp] axiom s1153 (x : Prop) : f (g1154 x) = f (g1153 x) @[simp] axiom s1154 (x : Prop) : f (g1155 x) = f (g1154 x) @[simp] axiom s1155 (x : Prop) : f (g1156 x) = f (g1155 x) @[simp] axiom s1156 (x : Prop) : f (g1157 x) = f (g1156 x) @[simp] axiom s1157 (x : Prop) : f (g1158 x) = f (g1157 x) @[simp] axiom s1158 (x : Prop) : f (g1159 x) = f (g1158 x) @[simp] axiom s1159 (x : Prop) : f (g1160 x) = f (g1159 x) @[simp] axiom s1160 (x : Prop) : f (g1161 x) = f (g1160 x) @[simp] axiom s1161 (x : Prop) : f (g1162 x) = f (g1161 x) @[simp] axiom s1162 (x : Prop) : f (g1163 x) = f (g1162 x) @[simp] axiom s1163 (x : Prop) : f (g1164 x) = f (g1163 x) @[simp] axiom s1164 (x : Prop) : f (g1165 x) = f (g1164 x) @[simp] axiom s1165 (x : Prop) : f (g1166 x) = f (g1165 x) @[simp] axiom s1166 (x : Prop) : f (g1167 x) = f (g1166 x) @[simp] axiom s1167 (x : Prop) : f (g1168 x) = f (g1167 x) @[simp] axiom s1168 (x : Prop) : f (g1169 x) = f (g1168 x) @[simp] axiom s1169 (x : Prop) : f (g1170 x) = f (g1169 x) @[simp] axiom s1170 (x : Prop) : f (g1171 x) = f (g1170 x) @[simp] axiom s1171 (x : Prop) : f (g1172 x) = f (g1171 x) @[simp] axiom s1172 (x : Prop) : f (g1173 x) = f (g1172 x) @[simp] axiom s1173 (x : Prop) : f (g1174 x) = f (g1173 x) @[simp] axiom s1174 (x : Prop) : f (g1175 x) = f (g1174 x) @[simp] axiom s1175 (x : Prop) : f (g1176 x) = f (g1175 x) @[simp] axiom s1176 (x : Prop) : f (g1177 x) = f (g1176 x) @[simp] axiom s1177 (x : Prop) : f (g1178 x) = f (g1177 x) @[simp] axiom s1178 (x : Prop) : f (g1179 x) = f (g1178 x) @[simp] axiom s1179 (x : Prop) : f (g1180 x) = f (g1179 x) @[simp] axiom s1180 (x : Prop) : f (g1181 x) = f (g1180 x) @[simp] axiom s1181 (x : Prop) : f (g1182 x) = f (g1181 x) @[simp] axiom s1182 (x : Prop) : f (g1183 x) = f (g1182 x) @[simp] axiom s1183 (x : Prop) : f (g1184 x) = f (g1183 x) @[simp] axiom s1184 (x : Prop) : f (g1185 x) = f (g1184 x) @[simp] axiom s1185 (x : Prop) : f (g1186 x) = f (g1185 x) @[simp] axiom s1186 (x : Prop) : f (g1187 x) = f (g1186 x) @[simp] axiom s1187 (x : Prop) : f (g1188 x) = f (g1187 x) @[simp] axiom s1188 (x : Prop) : f (g1189 x) = f (g1188 x) @[simp] axiom s1189 (x : Prop) : f (g1190 x) = f (g1189 x) @[simp] axiom s1190 (x : Prop) : f (g1191 x) = f (g1190 x) @[simp] axiom s1191 (x : Prop) : f (g1192 x) = f (g1191 x) @[simp] axiom s1192 (x : Prop) : f (g1193 x) = f (g1192 x) @[simp] axiom s1193 (x : Prop) : f (g1194 x) = f (g1193 x) @[simp] axiom s1194 (x : Prop) : f (g1195 x) = f (g1194 x) @[simp] axiom s1195 (x : Prop) : f (g1196 x) = f (g1195 x) @[simp] axiom s1196 (x : Prop) : f (g1197 x) = f (g1196 x) @[simp] axiom s1197 (x : Prop) : f (g1198 x) = f (g1197 x) @[simp] axiom s1198 (x : Prop) : f (g1199 x) = f (g1198 x) @[simp] axiom s1199 (x : Prop) : f (g1200 x) = f (g1199 x) @[simp] axiom s1200 (x : Prop) : f (g1201 x) = f (g1200 x) @[simp] axiom s1201 (x : Prop) : f (g1202 x) = f (g1201 x) @[simp] axiom s1202 (x : Prop) : f (g1203 x) = f (g1202 x) @[simp] axiom s1203 (x : Prop) : f (g1204 x) = f (g1203 x) @[simp] axiom s1204 (x : Prop) : f (g1205 x) = f (g1204 x) @[simp] axiom s1205 (x : Prop) : f (g1206 x) = f (g1205 x) @[simp] axiom s1206 (x : Prop) : f (g1207 x) = f (g1206 x) @[simp] axiom s1207 (x : Prop) : f (g1208 x) = f (g1207 x) @[simp] axiom s1208 (x : Prop) : f (g1209 x) = f (g1208 x) @[simp] axiom s1209 (x : Prop) : f (g1210 x) = f (g1209 x) @[simp] axiom s1210 (x : Prop) : f (g1211 x) = f (g1210 x) @[simp] axiom s1211 (x : Prop) : f (g1212 x) = f (g1211 x) @[simp] axiom s1212 (x : Prop) : f (g1213 x) = f (g1212 x) @[simp] axiom s1213 (x : Prop) : f (g1214 x) = f (g1213 x) @[simp] axiom s1214 (x : Prop) : f (g1215 x) = f (g1214 x) @[simp] axiom s1215 (x : Prop) : f (g1216 x) = f (g1215 x) @[simp] axiom s1216 (x : Prop) : f (g1217 x) = f (g1216 x) @[simp] axiom s1217 (x : Prop) : f (g1218 x) = f (g1217 x) @[simp] axiom s1218 (x : Prop) : f (g1219 x) = f (g1218 x) @[simp] axiom s1219 (x : Prop) : f (g1220 x) = f (g1219 x) @[simp] axiom s1220 (x : Prop) : f (g1221 x) = f (g1220 x) @[simp] axiom s1221 (x : Prop) : f (g1222 x) = f (g1221 x) @[simp] axiom s1222 (x : Prop) : f (g1223 x) = f (g1222 x) @[simp] axiom s1223 (x : Prop) : f (g1224 x) = f (g1223 x) @[simp] axiom s1224 (x : Prop) : f (g1225 x) = f (g1224 x) @[simp] axiom s1225 (x : Prop) : f (g1226 x) = f (g1225 x) @[simp] axiom s1226 (x : Prop) : f (g1227 x) = f (g1226 x) @[simp] axiom s1227 (x : Prop) : f (g1228 x) = f (g1227 x) @[simp] axiom s1228 (x : Prop) : f (g1229 x) = f (g1228 x) @[simp] axiom s1229 (x : Prop) : f (g1230 x) = f (g1229 x) @[simp] axiom s1230 (x : Prop) : f (g1231 x) = f (g1230 x) @[simp] axiom s1231 (x : Prop) : f (g1232 x) = f (g1231 x) @[simp] axiom s1232 (x : Prop) : f (g1233 x) = f (g1232 x) @[simp] axiom s1233 (x : Prop) : f (g1234 x) = f (g1233 x) @[simp] axiom s1234 (x : Prop) : f (g1235 x) = f (g1234 x) @[simp] axiom s1235 (x : Prop) : f (g1236 x) = f (g1235 x) @[simp] axiom s1236 (x : Prop) : f (g1237 x) = f (g1236 x) @[simp] axiom s1237 (x : Prop) : f (g1238 x) = f (g1237 x) @[simp] axiom s1238 (x : Prop) : f (g1239 x) = f (g1238 x) @[simp] axiom s1239 (x : Prop) : f (g1240 x) = f (g1239 x) @[simp] axiom s1240 (x : Prop) : f (g1241 x) = f (g1240 x) @[simp] axiom s1241 (x : Prop) : f (g1242 x) = f (g1241 x) @[simp] axiom s1242 (x : Prop) : f (g1243 x) = f (g1242 x) @[simp] axiom s1243 (x : Prop) : f (g1244 x) = f (g1243 x) @[simp] axiom s1244 (x : Prop) : f (g1245 x) = f (g1244 x) @[simp] axiom s1245 (x : Prop) : f (g1246 x) = f (g1245 x) @[simp] axiom s1246 (x : Prop) : f (g1247 x) = f (g1246 x) @[simp] axiom s1247 (x : Prop) : f (g1248 x) = f (g1247 x) @[simp] axiom s1248 (x : Prop) : f (g1249 x) = f (g1248 x) @[simp] axiom s1249 (x : Prop) : f (g1250 x) = f (g1249 x) @[simp] axiom s1250 (x : Prop) : f (g1251 x) = f (g1250 x) @[simp] axiom s1251 (x : Prop) : f (g1252 x) = f (g1251 x) @[simp] axiom s1252 (x : Prop) : f (g1253 x) = f (g1252 x) @[simp] axiom s1253 (x : Prop) : f (g1254 x) = f (g1253 x) @[simp] axiom s1254 (x : Prop) : f (g1255 x) = f (g1254 x) @[simp] axiom s1255 (x : Prop) : f (g1256 x) = f (g1255 x) @[simp] axiom s1256 (x : Prop) : f (g1257 x) = f (g1256 x) @[simp] axiom s1257 (x : Prop) : f (g1258 x) = f (g1257 x) @[simp] axiom s1258 (x : Prop) : f (g1259 x) = f (g1258 x) @[simp] axiom s1259 (x : Prop) : f (g1260 x) = f (g1259 x) @[simp] axiom s1260 (x : Prop) : f (g1261 x) = f (g1260 x) @[simp] axiom s1261 (x : Prop) : f (g1262 x) = f (g1261 x) @[simp] axiom s1262 (x : Prop) : f (g1263 x) = f (g1262 x) @[simp] axiom s1263 (x : Prop) : f (g1264 x) = f (g1263 x) @[simp] axiom s1264 (x : Prop) : f (g1265 x) = f (g1264 x) @[simp] axiom s1265 (x : Prop) : f (g1266 x) = f (g1265 x) @[simp] axiom s1266 (x : Prop) : f (g1267 x) = f (g1266 x) @[simp] axiom s1267 (x : Prop) : f (g1268 x) = f (g1267 x) @[simp] axiom s1268 (x : Prop) : f (g1269 x) = f (g1268 x) @[simp] axiom s1269 (x : Prop) : f (g1270 x) = f (g1269 x) @[simp] axiom s1270 (x : Prop) : f (g1271 x) = f (g1270 x) @[simp] axiom s1271 (x : Prop) : f (g1272 x) = f (g1271 x) @[simp] axiom s1272 (x : Prop) : f (g1273 x) = f (g1272 x) @[simp] axiom s1273 (x : Prop) : f (g1274 x) = f (g1273 x) @[simp] axiom s1274 (x : Prop) : f (g1275 x) = f (g1274 x) @[simp] axiom s1275 (x : Prop) : f (g1276 x) = f (g1275 x) @[simp] axiom s1276 (x : Prop) : f (g1277 x) = f (g1276 x) @[simp] axiom s1277 (x : Prop) : f (g1278 x) = f (g1277 x) @[simp] axiom s1278 (x : Prop) : f (g1279 x) = f (g1278 x) @[simp] axiom s1279 (x : Prop) : f (g1280 x) = f (g1279 x) @[simp] axiom s1280 (x : Prop) : f (g1281 x) = f (g1280 x) @[simp] axiom s1281 (x : Prop) : f (g1282 x) = f (g1281 x) @[simp] axiom s1282 (x : Prop) : f (g1283 x) = f (g1282 x) @[simp] axiom s1283 (x : Prop) : f (g1284 x) = f (g1283 x) @[simp] axiom s1284 (x : Prop) : f (g1285 x) = f (g1284 x) @[simp] axiom s1285 (x : Prop) : f (g1286 x) = f (g1285 x) @[simp] axiom s1286 (x : Prop) : f (g1287 x) = f (g1286 x) @[simp] axiom s1287 (x : Prop) : f (g1288 x) = f (g1287 x) @[simp] axiom s1288 (x : Prop) : f (g1289 x) = f (g1288 x) @[simp] axiom s1289 (x : Prop) : f (g1290 x) = f (g1289 x) @[simp] axiom s1290 (x : Prop) : f (g1291 x) = f (g1290 x) @[simp] axiom s1291 (x : Prop) : f (g1292 x) = f (g1291 x) @[simp] axiom s1292 (x : Prop) : f (g1293 x) = f (g1292 x) @[simp] axiom s1293 (x : Prop) : f (g1294 x) = f (g1293 x) @[simp] axiom s1294 (x : Prop) : f (g1295 x) = f (g1294 x) @[simp] axiom s1295 (x : Prop) : f (g1296 x) = f (g1295 x) @[simp] axiom s1296 (x : Prop) : f (g1297 x) = f (g1296 x) @[simp] axiom s1297 (x : Prop) : f (g1298 x) = f (g1297 x) @[simp] axiom s1298 (x : Prop) : f (g1299 x) = f (g1298 x) @[simp] axiom s1299 (x : Prop) : f (g1300 x) = f (g1299 x) @[simp] axiom s1300 (x : Prop) : f (g1301 x) = f (g1300 x) @[simp] axiom s1301 (x : Prop) : f (g1302 x) = f (g1301 x) @[simp] axiom s1302 (x : Prop) : f (g1303 x) = f (g1302 x) @[simp] axiom s1303 (x : Prop) : f (g1304 x) = f (g1303 x) @[simp] axiom s1304 (x : Prop) : f (g1305 x) = f (g1304 x) @[simp] axiom s1305 (x : Prop) : f (g1306 x) = f (g1305 x) @[simp] axiom s1306 (x : Prop) : f (g1307 x) = f (g1306 x) @[simp] axiom s1307 (x : Prop) : f (g1308 x) = f (g1307 x) @[simp] axiom s1308 (x : Prop) : f (g1309 x) = f (g1308 x) @[simp] axiom s1309 (x : Prop) : f (g1310 x) = f (g1309 x) @[simp] axiom s1310 (x : Prop) : f (g1311 x) = f (g1310 x) @[simp] axiom s1311 (x : Prop) : f (g1312 x) = f (g1311 x) @[simp] axiom s1312 (x : Prop) : f (g1313 x) = f (g1312 x) @[simp] axiom s1313 (x : Prop) : f (g1314 x) = f (g1313 x) @[simp] axiom s1314 (x : Prop) : f (g1315 x) = f (g1314 x) @[simp] axiom s1315 (x : Prop) : f (g1316 x) = f (g1315 x) @[simp] axiom s1316 (x : Prop) : f (g1317 x) = f (g1316 x) @[simp] axiom s1317 (x : Prop) : f (g1318 x) = f (g1317 x) @[simp] axiom s1318 (x : Prop) : f (g1319 x) = f (g1318 x) @[simp] axiom s1319 (x : Prop) : f (g1320 x) = f (g1319 x) @[simp] axiom s1320 (x : Prop) : f (g1321 x) = f (g1320 x) @[simp] axiom s1321 (x : Prop) : f (g1322 x) = f (g1321 x) @[simp] axiom s1322 (x : Prop) : f (g1323 x) = f (g1322 x) @[simp] axiom s1323 (x : Prop) : f (g1324 x) = f (g1323 x) @[simp] axiom s1324 (x : Prop) : f (g1325 x) = f (g1324 x) @[simp] axiom s1325 (x : Prop) : f (g1326 x) = f (g1325 x) @[simp] axiom s1326 (x : Prop) : f (g1327 x) = f (g1326 x) @[simp] axiom s1327 (x : Prop) : f (g1328 x) = f (g1327 x) @[simp] axiom s1328 (x : Prop) : f (g1329 x) = f (g1328 x) @[simp] axiom s1329 (x : Prop) : f (g1330 x) = f (g1329 x) @[simp] axiom s1330 (x : Prop) : f (g1331 x) = f (g1330 x) @[simp] axiom s1331 (x : Prop) : f (g1332 x) = f (g1331 x) @[simp] axiom s1332 (x : Prop) : f (g1333 x) = f (g1332 x) @[simp] axiom s1333 (x : Prop) : f (g1334 x) = f (g1333 x) @[simp] axiom s1334 (x : Prop) : f (g1335 x) = f (g1334 x) @[simp] axiom s1335 (x : Prop) : f (g1336 x) = f (g1335 x) @[simp] axiom s1336 (x : Prop) : f (g1337 x) = f (g1336 x) @[simp] axiom s1337 (x : Prop) : f (g1338 x) = f (g1337 x) @[simp] axiom s1338 (x : Prop) : f (g1339 x) = f (g1338 x) @[simp] axiom s1339 (x : Prop) : f (g1340 x) = f (g1339 x) @[simp] axiom s1340 (x : Prop) : f (g1341 x) = f (g1340 x) @[simp] axiom s1341 (x : Prop) : f (g1342 x) = f (g1341 x) @[simp] axiom s1342 (x : Prop) : f (g1343 x) = f (g1342 x) @[simp] axiom s1343 (x : Prop) : f (g1344 x) = f (g1343 x) @[simp] axiom s1344 (x : Prop) : f (g1345 x) = f (g1344 x) @[simp] axiom s1345 (x : Prop) : f (g1346 x) = f (g1345 x) @[simp] axiom s1346 (x : Prop) : f (g1347 x) = f (g1346 x) @[simp] axiom s1347 (x : Prop) : f (g1348 x) = f (g1347 x) @[simp] axiom s1348 (x : Prop) : f (g1349 x) = f (g1348 x) @[simp] axiom s1349 (x : Prop) : f (g1350 x) = f (g1349 x) @[simp] axiom s1350 (x : Prop) : f (g1351 x) = f (g1350 x) @[simp] axiom s1351 (x : Prop) : f (g1352 x) = f (g1351 x) @[simp] axiom s1352 (x : Prop) : f (g1353 x) = f (g1352 x) @[simp] axiom s1353 (x : Prop) : f (g1354 x) = f (g1353 x) @[simp] axiom s1354 (x : Prop) : f (g1355 x) = f (g1354 x) @[simp] axiom s1355 (x : Prop) : f (g1356 x) = f (g1355 x) @[simp] axiom s1356 (x : Prop) : f (g1357 x) = f (g1356 x) @[simp] axiom s1357 (x : Prop) : f (g1358 x) = f (g1357 x) @[simp] axiom s1358 (x : Prop) : f (g1359 x) = f (g1358 x) @[simp] axiom s1359 (x : Prop) : f (g1360 x) = f (g1359 x) @[simp] axiom s1360 (x : Prop) : f (g1361 x) = f (g1360 x) @[simp] axiom s1361 (x : Prop) : f (g1362 x) = f (g1361 x) @[simp] axiom s1362 (x : Prop) : f (g1363 x) = f (g1362 x) @[simp] axiom s1363 (x : Prop) : f (g1364 x) = f (g1363 x) @[simp] axiom s1364 (x : Prop) : f (g1365 x) = f (g1364 x) @[simp] axiom s1365 (x : Prop) : f (g1366 x) = f (g1365 x) @[simp] axiom s1366 (x : Prop) : f (g1367 x) = f (g1366 x) @[simp] axiom s1367 (x : Prop) : f (g1368 x) = f (g1367 x) @[simp] axiom s1368 (x : Prop) : f (g1369 x) = f (g1368 x) @[simp] axiom s1369 (x : Prop) : f (g1370 x) = f (g1369 x) @[simp] axiom s1370 (x : Prop) : f (g1371 x) = f (g1370 x) @[simp] axiom s1371 (x : Prop) : f (g1372 x) = f (g1371 x) @[simp] axiom s1372 (x : Prop) : f (g1373 x) = f (g1372 x) @[simp] axiom s1373 (x : Prop) : f (g1374 x) = f (g1373 x) @[simp] axiom s1374 (x : Prop) : f (g1375 x) = f (g1374 x) @[simp] axiom s1375 (x : Prop) : f (g1376 x) = f (g1375 x) @[simp] axiom s1376 (x : Prop) : f (g1377 x) = f (g1376 x) @[simp] axiom s1377 (x : Prop) : f (g1378 x) = f (g1377 x) @[simp] axiom s1378 (x : Prop) : f (g1379 x) = f (g1378 x) @[simp] axiom s1379 (x : Prop) : f (g1380 x) = f (g1379 x) @[simp] axiom s1380 (x : Prop) : f (g1381 x) = f (g1380 x) @[simp] axiom s1381 (x : Prop) : f (g1382 x) = f (g1381 x) @[simp] axiom s1382 (x : Prop) : f (g1383 x) = f (g1382 x) @[simp] axiom s1383 (x : Prop) : f (g1384 x) = f (g1383 x) @[simp] axiom s1384 (x : Prop) : f (g1385 x) = f (g1384 x) @[simp] axiom s1385 (x : Prop) : f (g1386 x) = f (g1385 x) @[simp] axiom s1386 (x : Prop) : f (g1387 x) = f (g1386 x) @[simp] axiom s1387 (x : Prop) : f (g1388 x) = f (g1387 x) @[simp] axiom s1388 (x : Prop) : f (g1389 x) = f (g1388 x) @[simp] axiom s1389 (x : Prop) : f (g1390 x) = f (g1389 x) @[simp] axiom s1390 (x : Prop) : f (g1391 x) = f (g1390 x) @[simp] axiom s1391 (x : Prop) : f (g1392 x) = f (g1391 x) @[simp] axiom s1392 (x : Prop) : f (g1393 x) = f (g1392 x) @[simp] axiom s1393 (x : Prop) : f (g1394 x) = f (g1393 x) @[simp] axiom s1394 (x : Prop) : f (g1395 x) = f (g1394 x) @[simp] axiom s1395 (x : Prop) : f (g1396 x) = f (g1395 x) @[simp] axiom s1396 (x : Prop) : f (g1397 x) = f (g1396 x) @[simp] axiom s1397 (x : Prop) : f (g1398 x) = f (g1397 x) @[simp] axiom s1398 (x : Prop) : f (g1399 x) = f (g1398 x) @[simp] axiom s1399 (x : Prop) : f (g1400 x) = f (g1399 x) @[simp] axiom s1400 (x : Prop) : f (g1401 x) = f (g1400 x) @[simp] axiom s1401 (x : Prop) : f (g1402 x) = f (g1401 x) @[simp] axiom s1402 (x : Prop) : f (g1403 x) = f (g1402 x) @[simp] axiom s1403 (x : Prop) : f (g1404 x) = f (g1403 x) @[simp] axiom s1404 (x : Prop) : f (g1405 x) = f (g1404 x) @[simp] axiom s1405 (x : Prop) : f (g1406 x) = f (g1405 x) @[simp] axiom s1406 (x : Prop) : f (g1407 x) = f (g1406 x) @[simp] axiom s1407 (x : Prop) : f (g1408 x) = f (g1407 x) @[simp] axiom s1408 (x : Prop) : f (g1409 x) = f (g1408 x) @[simp] axiom s1409 (x : Prop) : f (g1410 x) = f (g1409 x) @[simp] axiom s1410 (x : Prop) : f (g1411 x) = f (g1410 x) @[simp] axiom s1411 (x : Prop) : f (g1412 x) = f (g1411 x) @[simp] axiom s1412 (x : Prop) : f (g1413 x) = f (g1412 x) @[simp] axiom s1413 (x : Prop) : f (g1414 x) = f (g1413 x) @[simp] axiom s1414 (x : Prop) : f (g1415 x) = f (g1414 x) @[simp] axiom s1415 (x : Prop) : f (g1416 x) = f (g1415 x) @[simp] axiom s1416 (x : Prop) : f (g1417 x) = f (g1416 x) @[simp] axiom s1417 (x : Prop) : f (g1418 x) = f (g1417 x) @[simp] axiom s1418 (x : Prop) : f (g1419 x) = f (g1418 x) @[simp] axiom s1419 (x : Prop) : f (g1420 x) = f (g1419 x) @[simp] axiom s1420 (x : Prop) : f (g1421 x) = f (g1420 x) @[simp] axiom s1421 (x : Prop) : f (g1422 x) = f (g1421 x) @[simp] axiom s1422 (x : Prop) : f (g1423 x) = f (g1422 x) @[simp] axiom s1423 (x : Prop) : f (g1424 x) = f (g1423 x) @[simp] axiom s1424 (x : Prop) : f (g1425 x) = f (g1424 x) @[simp] axiom s1425 (x : Prop) : f (g1426 x) = f (g1425 x) @[simp] axiom s1426 (x : Prop) : f (g1427 x) = f (g1426 x) @[simp] axiom s1427 (x : Prop) : f (g1428 x) = f (g1427 x) @[simp] axiom s1428 (x : Prop) : f (g1429 x) = f (g1428 x) @[simp] axiom s1429 (x : Prop) : f (g1430 x) = f (g1429 x) @[simp] axiom s1430 (x : Prop) : f (g1431 x) = f (g1430 x) @[simp] axiom s1431 (x : Prop) : f (g1432 x) = f (g1431 x) @[simp] axiom s1432 (x : Prop) : f (g1433 x) = f (g1432 x) @[simp] axiom s1433 (x : Prop) : f (g1434 x) = f (g1433 x) @[simp] axiom s1434 (x : Prop) : f (g1435 x) = f (g1434 x) @[simp] axiom s1435 (x : Prop) : f (g1436 x) = f (g1435 x) @[simp] axiom s1436 (x : Prop) : f (g1437 x) = f (g1436 x) @[simp] axiom s1437 (x : Prop) : f (g1438 x) = f (g1437 x) @[simp] axiom s1438 (x : Prop) : f (g1439 x) = f (g1438 x) @[simp] axiom s1439 (x : Prop) : f (g1440 x) = f (g1439 x) @[simp] axiom s1440 (x : Prop) : f (g1441 x) = f (g1440 x) @[simp] axiom s1441 (x : Prop) : f (g1442 x) = f (g1441 x) @[simp] axiom s1442 (x : Prop) : f (g1443 x) = f (g1442 x) @[simp] axiom s1443 (x : Prop) : f (g1444 x) = f (g1443 x) @[simp] axiom s1444 (x : Prop) : f (g1445 x) = f (g1444 x) @[simp] axiom s1445 (x : Prop) : f (g1446 x) = f (g1445 x) @[simp] axiom s1446 (x : Prop) : f (g1447 x) = f (g1446 x) @[simp] axiom s1447 (x : Prop) : f (g1448 x) = f (g1447 x) @[simp] axiom s1448 (x : Prop) : f (g1449 x) = f (g1448 x) @[simp] axiom s1449 (x : Prop) : f (g1450 x) = f (g1449 x) @[simp] axiom s1450 (x : Prop) : f (g1451 x) = f (g1450 x) @[simp] axiom s1451 (x : Prop) : f (g1452 x) = f (g1451 x) @[simp] axiom s1452 (x : Prop) : f (g1453 x) = f (g1452 x) @[simp] axiom s1453 (x : Prop) : f (g1454 x) = f (g1453 x) @[simp] axiom s1454 (x : Prop) : f (g1455 x) = f (g1454 x) @[simp] axiom s1455 (x : Prop) : f (g1456 x) = f (g1455 x) @[simp] axiom s1456 (x : Prop) : f (g1457 x) = f (g1456 x) @[simp] axiom s1457 (x : Prop) : f (g1458 x) = f (g1457 x) @[simp] axiom s1458 (x : Prop) : f (g1459 x) = f (g1458 x) @[simp] axiom s1459 (x : Prop) : f (g1460 x) = f (g1459 x) @[simp] axiom s1460 (x : Prop) : f (g1461 x) = f (g1460 x) @[simp] axiom s1461 (x : Prop) : f (g1462 x) = f (g1461 x) @[simp] axiom s1462 (x : Prop) : f (g1463 x) = f (g1462 x) @[simp] axiom s1463 (x : Prop) : f (g1464 x) = f (g1463 x) @[simp] axiom s1464 (x : Prop) : f (g1465 x) = f (g1464 x) @[simp] axiom s1465 (x : Prop) : f (g1466 x) = f (g1465 x) @[simp] axiom s1466 (x : Prop) : f (g1467 x) = f (g1466 x) @[simp] axiom s1467 (x : Prop) : f (g1468 x) = f (g1467 x) @[simp] axiom s1468 (x : Prop) : f (g1469 x) = f (g1468 x) @[simp] axiom s1469 (x : Prop) : f (g1470 x) = f (g1469 x) @[simp] axiom s1470 (x : Prop) : f (g1471 x) = f (g1470 x) @[simp] axiom s1471 (x : Prop) : f (g1472 x) = f (g1471 x) @[simp] axiom s1472 (x : Prop) : f (g1473 x) = f (g1472 x) @[simp] axiom s1473 (x : Prop) : f (g1474 x) = f (g1473 x) @[simp] axiom s1474 (x : Prop) : f (g1475 x) = f (g1474 x) @[simp] axiom s1475 (x : Prop) : f (g1476 x) = f (g1475 x) @[simp] axiom s1476 (x : Prop) : f (g1477 x) = f (g1476 x) @[simp] axiom s1477 (x : Prop) : f (g1478 x) = f (g1477 x) @[simp] axiom s1478 (x : Prop) : f (g1479 x) = f (g1478 x) @[simp] axiom s1479 (x : Prop) : f (g1480 x) = f (g1479 x) @[simp] axiom s1480 (x : Prop) : f (g1481 x) = f (g1480 x) @[simp] axiom s1481 (x : Prop) : f (g1482 x) = f (g1481 x) @[simp] axiom s1482 (x : Prop) : f (g1483 x) = f (g1482 x) @[simp] axiom s1483 (x : Prop) : f (g1484 x) = f (g1483 x) @[simp] axiom s1484 (x : Prop) : f (g1485 x) = f (g1484 x) @[simp] axiom s1485 (x : Prop) : f (g1486 x) = f (g1485 x) @[simp] axiom s1486 (x : Prop) : f (g1487 x) = f (g1486 x) @[simp] axiom s1487 (x : Prop) : f (g1488 x) = f (g1487 x) @[simp] axiom s1488 (x : Prop) : f (g1489 x) = f (g1488 x) @[simp] axiom s1489 (x : Prop) : f (g1490 x) = f (g1489 x) @[simp] axiom s1490 (x : Prop) : f (g1491 x) = f (g1490 x) @[simp] axiom s1491 (x : Prop) : f (g1492 x) = f (g1491 x) @[simp] axiom s1492 (x : Prop) : f (g1493 x) = f (g1492 x) @[simp] axiom s1493 (x : Prop) : f (g1494 x) = f (g1493 x) @[simp] axiom s1494 (x : Prop) : f (g1495 x) = f (g1494 x) @[simp] axiom s1495 (x : Prop) : f (g1496 x) = f (g1495 x) @[simp] axiom s1496 (x : Prop) : f (g1497 x) = f (g1496 x) @[simp] axiom s1497 (x : Prop) : f (g1498 x) = f (g1497 x) @[simp] axiom s1498 (x : Prop) : f (g1499 x) = f (g1498 x) @[simp] axiom s1499 (x : Prop) : f (g1500 x) = f (g1499 x) @[simp] axiom s1500 (x : Prop) : f (g1501 x) = f (g1500 x) @[simp] axiom s1501 (x : Prop) : f (g1502 x) = f (g1501 x) @[simp] axiom s1502 (x : Prop) : f (g1503 x) = f (g1502 x) @[simp] axiom s1503 (x : Prop) : f (g1504 x) = f (g1503 x) @[simp] axiom s1504 (x : Prop) : f (g1505 x) = f (g1504 x) @[simp] axiom s1505 (x : Prop) : f (g1506 x) = f (g1505 x) @[simp] axiom s1506 (x : Prop) : f (g1507 x) = f (g1506 x) @[simp] axiom s1507 (x : Prop) : f (g1508 x) = f (g1507 x) @[simp] axiom s1508 (x : Prop) : f (g1509 x) = f (g1508 x) @[simp] axiom s1509 (x : Prop) : f (g1510 x) = f (g1509 x) @[simp] axiom s1510 (x : Prop) : f (g1511 x) = f (g1510 x) @[simp] axiom s1511 (x : Prop) : f (g1512 x) = f (g1511 x) @[simp] axiom s1512 (x : Prop) : f (g1513 x) = f (g1512 x) @[simp] axiom s1513 (x : Prop) : f (g1514 x) = f (g1513 x) @[simp] axiom s1514 (x : Prop) : f (g1515 x) = f (g1514 x) @[simp] axiom s1515 (x : Prop) : f (g1516 x) = f (g1515 x) @[simp] axiom s1516 (x : Prop) : f (g1517 x) = f (g1516 x) @[simp] axiom s1517 (x : Prop) : f (g1518 x) = f (g1517 x) @[simp] axiom s1518 (x : Prop) : f (g1519 x) = f (g1518 x) @[simp] axiom s1519 (x : Prop) : f (g1520 x) = f (g1519 x) @[simp] axiom s1520 (x : Prop) : f (g1521 x) = f (g1520 x) @[simp] axiom s1521 (x : Prop) : f (g1522 x) = f (g1521 x) @[simp] axiom s1522 (x : Prop) : f (g1523 x) = f (g1522 x) @[simp] axiom s1523 (x : Prop) : f (g1524 x) = f (g1523 x) @[simp] axiom s1524 (x : Prop) : f (g1525 x) = f (g1524 x) @[simp] axiom s1525 (x : Prop) : f (g1526 x) = f (g1525 x) @[simp] axiom s1526 (x : Prop) : f (g1527 x) = f (g1526 x) @[simp] axiom s1527 (x : Prop) : f (g1528 x) = f (g1527 x) @[simp] axiom s1528 (x : Prop) : f (g1529 x) = f (g1528 x) @[simp] axiom s1529 (x : Prop) : f (g1530 x) = f (g1529 x) @[simp] axiom s1530 (x : Prop) : f (g1531 x) = f (g1530 x) @[simp] axiom s1531 (x : Prop) : f (g1532 x) = f (g1531 x) @[simp] axiom s1532 (x : Prop) : f (g1533 x) = f (g1532 x) @[simp] axiom s1533 (x : Prop) : f (g1534 x) = f (g1533 x) @[simp] axiom s1534 (x : Prop) : f (g1535 x) = f (g1534 x) @[simp] axiom s1535 (x : Prop) : f (g1536 x) = f (g1535 x) @[simp] axiom s1536 (x : Prop) : f (g1537 x) = f (g1536 x) @[simp] axiom s1537 (x : Prop) : f (g1538 x) = f (g1537 x) @[simp] axiom s1538 (x : Prop) : f (g1539 x) = f (g1538 x) @[simp] axiom s1539 (x : Prop) : f (g1540 x) = f (g1539 x) @[simp] axiom s1540 (x : Prop) : f (g1541 x) = f (g1540 x) @[simp] axiom s1541 (x : Prop) : f (g1542 x) = f (g1541 x) @[simp] axiom s1542 (x : Prop) : f (g1543 x) = f (g1542 x) @[simp] axiom s1543 (x : Prop) : f (g1544 x) = f (g1543 x) @[simp] axiom s1544 (x : Prop) : f (g1545 x) = f (g1544 x) @[simp] axiom s1545 (x : Prop) : f (g1546 x) = f (g1545 x) @[simp] axiom s1546 (x : Prop) : f (g1547 x) = f (g1546 x) @[simp] axiom s1547 (x : Prop) : f (g1548 x) = f (g1547 x) @[simp] axiom s1548 (x : Prop) : f (g1549 x) = f (g1548 x) @[simp] axiom s1549 (x : Prop) : f (g1550 x) = f (g1549 x) @[simp] axiom s1550 (x : Prop) : f (g1551 x) = f (g1550 x) @[simp] axiom s1551 (x : Prop) : f (g1552 x) = f (g1551 x) @[simp] axiom s1552 (x : Prop) : f (g1553 x) = f (g1552 x) @[simp] axiom s1553 (x : Prop) : f (g1554 x) = f (g1553 x) @[simp] axiom s1554 (x : Prop) : f (g1555 x) = f (g1554 x) @[simp] axiom s1555 (x : Prop) : f (g1556 x) = f (g1555 x) @[simp] axiom s1556 (x : Prop) : f (g1557 x) = f (g1556 x) @[simp] axiom s1557 (x : Prop) : f (g1558 x) = f (g1557 x) @[simp] axiom s1558 (x : Prop) : f (g1559 x) = f (g1558 x) @[simp] axiom s1559 (x : Prop) : f (g1560 x) = f (g1559 x) @[simp] axiom s1560 (x : Prop) : f (g1561 x) = f (g1560 x) @[simp] axiom s1561 (x : Prop) : f (g1562 x) = f (g1561 x) @[simp] axiom s1562 (x : Prop) : f (g1563 x) = f (g1562 x) @[simp] axiom s1563 (x : Prop) : f (g1564 x) = f (g1563 x) @[simp] axiom s1564 (x : Prop) : f (g1565 x) = f (g1564 x) @[simp] axiom s1565 (x : Prop) : f (g1566 x) = f (g1565 x) @[simp] axiom s1566 (x : Prop) : f (g1567 x) = f (g1566 x) @[simp] axiom s1567 (x : Prop) : f (g1568 x) = f (g1567 x) @[simp] axiom s1568 (x : Prop) : f (g1569 x) = f (g1568 x) @[simp] axiom s1569 (x : Prop) : f (g1570 x) = f (g1569 x) @[simp] axiom s1570 (x : Prop) : f (g1571 x) = f (g1570 x) @[simp] axiom s1571 (x : Prop) : f (g1572 x) = f (g1571 x) @[simp] axiom s1572 (x : Prop) : f (g1573 x) = f (g1572 x) @[simp] axiom s1573 (x : Prop) : f (g1574 x) = f (g1573 x) @[simp] axiom s1574 (x : Prop) : f (g1575 x) = f (g1574 x) @[simp] axiom s1575 (x : Prop) : f (g1576 x) = f (g1575 x) @[simp] axiom s1576 (x : Prop) : f (g1577 x) = f (g1576 x) @[simp] axiom s1577 (x : Prop) : f (g1578 x) = f (g1577 x) @[simp] axiom s1578 (x : Prop) : f (g1579 x) = f (g1578 x) @[simp] axiom s1579 (x : Prop) : f (g1580 x) = f (g1579 x) @[simp] axiom s1580 (x : Prop) : f (g1581 x) = f (g1580 x) @[simp] axiom s1581 (x : Prop) : f (g1582 x) = f (g1581 x) @[simp] axiom s1582 (x : Prop) : f (g1583 x) = f (g1582 x) @[simp] axiom s1583 (x : Prop) : f (g1584 x) = f (g1583 x) @[simp] axiom s1584 (x : Prop) : f (g1585 x) = f (g1584 x) @[simp] axiom s1585 (x : Prop) : f (g1586 x) = f (g1585 x) @[simp] axiom s1586 (x : Prop) : f (g1587 x) = f (g1586 x) @[simp] axiom s1587 (x : Prop) : f (g1588 x) = f (g1587 x) @[simp] axiom s1588 (x : Prop) : f (g1589 x) = f (g1588 x) @[simp] axiom s1589 (x : Prop) : f (g1590 x) = f (g1589 x) @[simp] axiom s1590 (x : Prop) : f (g1591 x) = f (g1590 x) @[simp] axiom s1591 (x : Prop) : f (g1592 x) = f (g1591 x) @[simp] axiom s1592 (x : Prop) : f (g1593 x) = f (g1592 x) @[simp] axiom s1593 (x : Prop) : f (g1594 x) = f (g1593 x) @[simp] axiom s1594 (x : Prop) : f (g1595 x) = f (g1594 x) @[simp] axiom s1595 (x : Prop) : f (g1596 x) = f (g1595 x) @[simp] axiom s1596 (x : Prop) : f (g1597 x) = f (g1596 x) @[simp] axiom s1597 (x : Prop) : f (g1598 x) = f (g1597 x) @[simp] axiom s1598 (x : Prop) : f (g1599 x) = f (g1598 x) @[simp] axiom s1599 (x : Prop) : f (g1600 x) = f (g1599 x) @[simp] axiom s1600 (x : Prop) : f (g1601 x) = f (g1600 x) @[simp] axiom s1601 (x : Prop) : f (g1602 x) = f (g1601 x) @[simp] axiom s1602 (x : Prop) : f (g1603 x) = f (g1602 x) @[simp] axiom s1603 (x : Prop) : f (g1604 x) = f (g1603 x) @[simp] axiom s1604 (x : Prop) : f (g1605 x) = f (g1604 x) @[simp] axiom s1605 (x : Prop) : f (g1606 x) = f (g1605 x) @[simp] axiom s1606 (x : Prop) : f (g1607 x) = f (g1606 x) @[simp] axiom s1607 (x : Prop) : f (g1608 x) = f (g1607 x) @[simp] axiom s1608 (x : Prop) : f (g1609 x) = f (g1608 x) @[simp] axiom s1609 (x : Prop) : f (g1610 x) = f (g1609 x) @[simp] axiom s1610 (x : Prop) : f (g1611 x) = f (g1610 x) @[simp] axiom s1611 (x : Prop) : f (g1612 x) = f (g1611 x) @[simp] axiom s1612 (x : Prop) : f (g1613 x) = f (g1612 x) @[simp] axiom s1613 (x : Prop) : f (g1614 x) = f (g1613 x) @[simp] axiom s1614 (x : Prop) : f (g1615 x) = f (g1614 x) @[simp] axiom s1615 (x : Prop) : f (g1616 x) = f (g1615 x) @[simp] axiom s1616 (x : Prop) : f (g1617 x) = f (g1616 x) @[simp] axiom s1617 (x : Prop) : f (g1618 x) = f (g1617 x) @[simp] axiom s1618 (x : Prop) : f (g1619 x) = f (g1618 x) @[simp] axiom s1619 (x : Prop) : f (g1620 x) = f (g1619 x) @[simp] axiom s1620 (x : Prop) : f (g1621 x) = f (g1620 x) @[simp] axiom s1621 (x : Prop) : f (g1622 x) = f (g1621 x) @[simp] axiom s1622 (x : Prop) : f (g1623 x) = f (g1622 x) @[simp] axiom s1623 (x : Prop) : f (g1624 x) = f (g1623 x) @[simp] axiom s1624 (x : Prop) : f (g1625 x) = f (g1624 x) @[simp] axiom s1625 (x : Prop) : f (g1626 x) = f (g1625 x) @[simp] axiom s1626 (x : Prop) : f (g1627 x) = f (g1626 x) @[simp] axiom s1627 (x : Prop) : f (g1628 x) = f (g1627 x) @[simp] axiom s1628 (x : Prop) : f (g1629 x) = f (g1628 x) @[simp] axiom s1629 (x : Prop) : f (g1630 x) = f (g1629 x) @[simp] axiom s1630 (x : Prop) : f (g1631 x) = f (g1630 x) @[simp] axiom s1631 (x : Prop) : f (g1632 x) = f (g1631 x) @[simp] axiom s1632 (x : Prop) : f (g1633 x) = f (g1632 x) @[simp] axiom s1633 (x : Prop) : f (g1634 x) = f (g1633 x) @[simp] axiom s1634 (x : Prop) : f (g1635 x) = f (g1634 x) @[simp] axiom s1635 (x : Prop) : f (g1636 x) = f (g1635 x) @[simp] axiom s1636 (x : Prop) : f (g1637 x) = f (g1636 x) @[simp] axiom s1637 (x : Prop) : f (g1638 x) = f (g1637 x) @[simp] axiom s1638 (x : Prop) : f (g1639 x) = f (g1638 x) @[simp] axiom s1639 (x : Prop) : f (g1640 x) = f (g1639 x) @[simp] axiom s1640 (x : Prop) : f (g1641 x) = f (g1640 x) @[simp] axiom s1641 (x : Prop) : f (g1642 x) = f (g1641 x) @[simp] axiom s1642 (x : Prop) : f (g1643 x) = f (g1642 x) @[simp] axiom s1643 (x : Prop) : f (g1644 x) = f (g1643 x) @[simp] axiom s1644 (x : Prop) : f (g1645 x) = f (g1644 x) @[simp] axiom s1645 (x : Prop) : f (g1646 x) = f (g1645 x) @[simp] axiom s1646 (x : Prop) : f (g1647 x) = f (g1646 x) @[simp] axiom s1647 (x : Prop) : f (g1648 x) = f (g1647 x) @[simp] axiom s1648 (x : Prop) : f (g1649 x) = f (g1648 x) @[simp] axiom s1649 (x : Prop) : f (g1650 x) = f (g1649 x) @[simp] axiom s1650 (x : Prop) : f (g1651 x) = f (g1650 x) @[simp] axiom s1651 (x : Prop) : f (g1652 x) = f (g1651 x) @[simp] axiom s1652 (x : Prop) : f (g1653 x) = f (g1652 x) @[simp] axiom s1653 (x : Prop) : f (g1654 x) = f (g1653 x) @[simp] axiom s1654 (x : Prop) : f (g1655 x) = f (g1654 x) @[simp] axiom s1655 (x : Prop) : f (g1656 x) = f (g1655 x) @[simp] axiom s1656 (x : Prop) : f (g1657 x) = f (g1656 x) @[simp] axiom s1657 (x : Prop) : f (g1658 x) = f (g1657 x) @[simp] axiom s1658 (x : Prop) : f (g1659 x) = f (g1658 x) @[simp] axiom s1659 (x : Prop) : f (g1660 x) = f (g1659 x) @[simp] axiom s1660 (x : Prop) : f (g1661 x) = f (g1660 x) @[simp] axiom s1661 (x : Prop) : f (g1662 x) = f (g1661 x) @[simp] axiom s1662 (x : Prop) : f (g1663 x) = f (g1662 x) @[simp] axiom s1663 (x : Prop) : f (g1664 x) = f (g1663 x) @[simp] axiom s1664 (x : Prop) : f (g1665 x) = f (g1664 x) @[simp] axiom s1665 (x : Prop) : f (g1666 x) = f (g1665 x) @[simp] axiom s1666 (x : Prop) : f (g1667 x) = f (g1666 x) @[simp] axiom s1667 (x : Prop) : f (g1668 x) = f (g1667 x) @[simp] axiom s1668 (x : Prop) : f (g1669 x) = f (g1668 x) @[simp] axiom s1669 (x : Prop) : f (g1670 x) = f (g1669 x) @[simp] axiom s1670 (x : Prop) : f (g1671 x) = f (g1670 x) @[simp] axiom s1671 (x : Prop) : f (g1672 x) = f (g1671 x) @[simp] axiom s1672 (x : Prop) : f (g1673 x) = f (g1672 x) @[simp] axiom s1673 (x : Prop) : f (g1674 x) = f (g1673 x) @[simp] axiom s1674 (x : Prop) : f (g1675 x) = f (g1674 x) @[simp] axiom s1675 (x : Prop) : f (g1676 x) = f (g1675 x) @[simp] axiom s1676 (x : Prop) : f (g1677 x) = f (g1676 x) @[simp] axiom s1677 (x : Prop) : f (g1678 x) = f (g1677 x) @[simp] axiom s1678 (x : Prop) : f (g1679 x) = f (g1678 x) @[simp] axiom s1679 (x : Prop) : f (g1680 x) = f (g1679 x) @[simp] axiom s1680 (x : Prop) : f (g1681 x) = f (g1680 x) @[simp] axiom s1681 (x : Prop) : f (g1682 x) = f (g1681 x) @[simp] axiom s1682 (x : Prop) : f (g1683 x) = f (g1682 x) @[simp] axiom s1683 (x : Prop) : f (g1684 x) = f (g1683 x) @[simp] axiom s1684 (x : Prop) : f (g1685 x) = f (g1684 x) @[simp] axiom s1685 (x : Prop) : f (g1686 x) = f (g1685 x) @[simp] axiom s1686 (x : Prop) : f (g1687 x) = f (g1686 x) @[simp] axiom s1687 (x : Prop) : f (g1688 x) = f (g1687 x) @[simp] axiom s1688 (x : Prop) : f (g1689 x) = f (g1688 x) @[simp] axiom s1689 (x : Prop) : f (g1690 x) = f (g1689 x) @[simp] axiom s1690 (x : Prop) : f (g1691 x) = f (g1690 x) @[simp] axiom s1691 (x : Prop) : f (g1692 x) = f (g1691 x) @[simp] axiom s1692 (x : Prop) : f (g1693 x) = f (g1692 x) @[simp] axiom s1693 (x : Prop) : f (g1694 x) = f (g1693 x) @[simp] axiom s1694 (x : Prop) : f (g1695 x) = f (g1694 x) @[simp] axiom s1695 (x : Prop) : f (g1696 x) = f (g1695 x) @[simp] axiom s1696 (x : Prop) : f (g1697 x) = f (g1696 x) @[simp] axiom s1697 (x : Prop) : f (g1698 x) = f (g1697 x) @[simp] axiom s1698 (x : Prop) : f (g1699 x) = f (g1698 x) @[simp] axiom s1699 (x : Prop) : f (g1700 x) = f (g1699 x) @[simp] axiom s1700 (x : Prop) : f (g1701 x) = f (g1700 x) @[simp] axiom s1701 (x : Prop) : f (g1702 x) = f (g1701 x) @[simp] axiom s1702 (x : Prop) : f (g1703 x) = f (g1702 x) @[simp] axiom s1703 (x : Prop) : f (g1704 x) = f (g1703 x) @[simp] axiom s1704 (x : Prop) : f (g1705 x) = f (g1704 x) @[simp] axiom s1705 (x : Prop) : f (g1706 x) = f (g1705 x) @[simp] axiom s1706 (x : Prop) : f (g1707 x) = f (g1706 x) @[simp] axiom s1707 (x : Prop) : f (g1708 x) = f (g1707 x) @[simp] axiom s1708 (x : Prop) : f (g1709 x) = f (g1708 x) @[simp] axiom s1709 (x : Prop) : f (g1710 x) = f (g1709 x) @[simp] axiom s1710 (x : Prop) : f (g1711 x) = f (g1710 x) @[simp] axiom s1711 (x : Prop) : f (g1712 x) = f (g1711 x) @[simp] axiom s1712 (x : Prop) : f (g1713 x) = f (g1712 x) @[simp] axiom s1713 (x : Prop) : f (g1714 x) = f (g1713 x) @[simp] axiom s1714 (x : Prop) : f (g1715 x) = f (g1714 x) @[simp] axiom s1715 (x : Prop) : f (g1716 x) = f (g1715 x) @[simp] axiom s1716 (x : Prop) : f (g1717 x) = f (g1716 x) @[simp] axiom s1717 (x : Prop) : f (g1718 x) = f (g1717 x) @[simp] axiom s1718 (x : Prop) : f (g1719 x) = f (g1718 x) @[simp] axiom s1719 (x : Prop) : f (g1720 x) = f (g1719 x) @[simp] axiom s1720 (x : Prop) : f (g1721 x) = f (g1720 x) @[simp] axiom s1721 (x : Prop) : f (g1722 x) = f (g1721 x) @[simp] axiom s1722 (x : Prop) : f (g1723 x) = f (g1722 x) @[simp] axiom s1723 (x : Prop) : f (g1724 x) = f (g1723 x) @[simp] axiom s1724 (x : Prop) : f (g1725 x) = f (g1724 x) @[simp] axiom s1725 (x : Prop) : f (g1726 x) = f (g1725 x) @[simp] axiom s1726 (x : Prop) : f (g1727 x) = f (g1726 x) @[simp] axiom s1727 (x : Prop) : f (g1728 x) = f (g1727 x) @[simp] axiom s1728 (x : Prop) : f (g1729 x) = f (g1728 x) @[simp] axiom s1729 (x : Prop) : f (g1730 x) = f (g1729 x) @[simp] axiom s1730 (x : Prop) : f (g1731 x) = f (g1730 x) @[simp] axiom s1731 (x : Prop) : f (g1732 x) = f (g1731 x) @[simp] axiom s1732 (x : Prop) : f (g1733 x) = f (g1732 x) @[simp] axiom s1733 (x : Prop) : f (g1734 x) = f (g1733 x) @[simp] axiom s1734 (x : Prop) : f (g1735 x) = f (g1734 x) @[simp] axiom s1735 (x : Prop) : f (g1736 x) = f (g1735 x) @[simp] axiom s1736 (x : Prop) : f (g1737 x) = f (g1736 x) @[simp] axiom s1737 (x : Prop) : f (g1738 x) = f (g1737 x) @[simp] axiom s1738 (x : Prop) : f (g1739 x) = f (g1738 x) @[simp] axiom s1739 (x : Prop) : f (g1740 x) = f (g1739 x) @[simp] axiom s1740 (x : Prop) : f (g1741 x) = f (g1740 x) @[simp] axiom s1741 (x : Prop) : f (g1742 x) = f (g1741 x) @[simp] axiom s1742 (x : Prop) : f (g1743 x) = f (g1742 x) @[simp] axiom s1743 (x : Prop) : f (g1744 x) = f (g1743 x) @[simp] axiom s1744 (x : Prop) : f (g1745 x) = f (g1744 x) @[simp] axiom s1745 (x : Prop) : f (g1746 x) = f (g1745 x) @[simp] axiom s1746 (x : Prop) : f (g1747 x) = f (g1746 x) @[simp] axiom s1747 (x : Prop) : f (g1748 x) = f (g1747 x) @[simp] axiom s1748 (x : Prop) : f (g1749 x) = f (g1748 x) @[simp] axiom s1749 (x : Prop) : f (g1750 x) = f (g1749 x) @[simp] axiom s1750 (x : Prop) : f (g1751 x) = f (g1750 x) @[simp] axiom s1751 (x : Prop) : f (g1752 x) = f (g1751 x) @[simp] axiom s1752 (x : Prop) : f (g1753 x) = f (g1752 x) @[simp] axiom s1753 (x : Prop) : f (g1754 x) = f (g1753 x) @[simp] axiom s1754 (x : Prop) : f (g1755 x) = f (g1754 x) @[simp] axiom s1755 (x : Prop) : f (g1756 x) = f (g1755 x) @[simp] axiom s1756 (x : Prop) : f (g1757 x) = f (g1756 x) @[simp] axiom s1757 (x : Prop) : f (g1758 x) = f (g1757 x) @[simp] axiom s1758 (x : Prop) : f (g1759 x) = f (g1758 x) @[simp] axiom s1759 (x : Prop) : f (g1760 x) = f (g1759 x) @[simp] axiom s1760 (x : Prop) : f (g1761 x) = f (g1760 x) @[simp] axiom s1761 (x : Prop) : f (g1762 x) = f (g1761 x) @[simp] axiom s1762 (x : Prop) : f (g1763 x) = f (g1762 x) @[simp] axiom s1763 (x : Prop) : f (g1764 x) = f (g1763 x) @[simp] axiom s1764 (x : Prop) : f (g1765 x) = f (g1764 x) @[simp] axiom s1765 (x : Prop) : f (g1766 x) = f (g1765 x) @[simp] axiom s1766 (x : Prop) : f (g1767 x) = f (g1766 x) @[simp] axiom s1767 (x : Prop) : f (g1768 x) = f (g1767 x) @[simp] axiom s1768 (x : Prop) : f (g1769 x) = f (g1768 x) @[simp] axiom s1769 (x : Prop) : f (g1770 x) = f (g1769 x) @[simp] axiom s1770 (x : Prop) : f (g1771 x) = f (g1770 x) @[simp] axiom s1771 (x : Prop) : f (g1772 x) = f (g1771 x) @[simp] axiom s1772 (x : Prop) : f (g1773 x) = f (g1772 x) @[simp] axiom s1773 (x : Prop) : f (g1774 x) = f (g1773 x) @[simp] axiom s1774 (x : Prop) : f (g1775 x) = f (g1774 x) @[simp] axiom s1775 (x : Prop) : f (g1776 x) = f (g1775 x) @[simp] axiom s1776 (x : Prop) : f (g1777 x) = f (g1776 x) @[simp] axiom s1777 (x : Prop) : f (g1778 x) = f (g1777 x) @[simp] axiom s1778 (x : Prop) : f (g1779 x) = f (g1778 x) @[simp] axiom s1779 (x : Prop) : f (g1780 x) = f (g1779 x) @[simp] axiom s1780 (x : Prop) : f (g1781 x) = f (g1780 x) @[simp] axiom s1781 (x : Prop) : f (g1782 x) = f (g1781 x) @[simp] axiom s1782 (x : Prop) : f (g1783 x) = f (g1782 x) @[simp] axiom s1783 (x : Prop) : f (g1784 x) = f (g1783 x) @[simp] axiom s1784 (x : Prop) : f (g1785 x) = f (g1784 x) @[simp] axiom s1785 (x : Prop) : f (g1786 x) = f (g1785 x) @[simp] axiom s1786 (x : Prop) : f (g1787 x) = f (g1786 x) @[simp] axiom s1787 (x : Prop) : f (g1788 x) = f (g1787 x) @[simp] axiom s1788 (x : Prop) : f (g1789 x) = f (g1788 x) @[simp] axiom s1789 (x : Prop) : f (g1790 x) = f (g1789 x) @[simp] axiom s1790 (x : Prop) : f (g1791 x) = f (g1790 x) @[simp] axiom s1791 (x : Prop) : f (g1792 x) = f (g1791 x) @[simp] axiom s1792 (x : Prop) : f (g1793 x) = f (g1792 x) @[simp] axiom s1793 (x : Prop) : f (g1794 x) = f (g1793 x) @[simp] axiom s1794 (x : Prop) : f (g1795 x) = f (g1794 x) @[simp] axiom s1795 (x : Prop) : f (g1796 x) = f (g1795 x) @[simp] axiom s1796 (x : Prop) : f (g1797 x) = f (g1796 x) @[simp] axiom s1797 (x : Prop) : f (g1798 x) = f (g1797 x) @[simp] axiom s1798 (x : Prop) : f (g1799 x) = f (g1798 x) @[simp] axiom s1799 (x : Prop) : f (g1800 x) = f (g1799 x) @[simp] axiom s1800 (x : Prop) : f (g1801 x) = f (g1800 x) @[simp] axiom s1801 (x : Prop) : f (g1802 x) = f (g1801 x) @[simp] axiom s1802 (x : Prop) : f (g1803 x) = f (g1802 x) @[simp] axiom s1803 (x : Prop) : f (g1804 x) = f (g1803 x) @[simp] axiom s1804 (x : Prop) : f (g1805 x) = f (g1804 x) @[simp] axiom s1805 (x : Prop) : f (g1806 x) = f (g1805 x) @[simp] axiom s1806 (x : Prop) : f (g1807 x) = f (g1806 x) @[simp] axiom s1807 (x : Prop) : f (g1808 x) = f (g1807 x) @[simp] axiom s1808 (x : Prop) : f (g1809 x) = f (g1808 x) @[simp] axiom s1809 (x : Prop) : f (g1810 x) = f (g1809 x) @[simp] axiom s1810 (x : Prop) : f (g1811 x) = f (g1810 x) @[simp] axiom s1811 (x : Prop) : f (g1812 x) = f (g1811 x) @[simp] axiom s1812 (x : Prop) : f (g1813 x) = f (g1812 x) @[simp] axiom s1813 (x : Prop) : f (g1814 x) = f (g1813 x) @[simp] axiom s1814 (x : Prop) : f (g1815 x) = f (g1814 x) @[simp] axiom s1815 (x : Prop) : f (g1816 x) = f (g1815 x) @[simp] axiom s1816 (x : Prop) : f (g1817 x) = f (g1816 x) @[simp] axiom s1817 (x : Prop) : f (g1818 x) = f (g1817 x) @[simp] axiom s1818 (x : Prop) : f (g1819 x) = f (g1818 x) @[simp] axiom s1819 (x : Prop) : f (g1820 x) = f (g1819 x) @[simp] axiom s1820 (x : Prop) : f (g1821 x) = f (g1820 x) @[simp] axiom s1821 (x : Prop) : f (g1822 x) = f (g1821 x) @[simp] axiom s1822 (x : Prop) : f (g1823 x) = f (g1822 x) @[simp] axiom s1823 (x : Prop) : f (g1824 x) = f (g1823 x) @[simp] axiom s1824 (x : Prop) : f (g1825 x) = f (g1824 x) @[simp] axiom s1825 (x : Prop) : f (g1826 x) = f (g1825 x) @[simp] axiom s1826 (x : Prop) : f (g1827 x) = f (g1826 x) @[simp] axiom s1827 (x : Prop) : f (g1828 x) = f (g1827 x) @[simp] axiom s1828 (x : Prop) : f (g1829 x) = f (g1828 x) @[simp] axiom s1829 (x : Prop) : f (g1830 x) = f (g1829 x) @[simp] axiom s1830 (x : Prop) : f (g1831 x) = f (g1830 x) @[simp] axiom s1831 (x : Prop) : f (g1832 x) = f (g1831 x) @[simp] axiom s1832 (x : Prop) : f (g1833 x) = f (g1832 x) @[simp] axiom s1833 (x : Prop) : f (g1834 x) = f (g1833 x) @[simp] axiom s1834 (x : Prop) : f (g1835 x) = f (g1834 x) @[simp] axiom s1835 (x : Prop) : f (g1836 x) = f (g1835 x) @[simp] axiom s1836 (x : Prop) : f (g1837 x) = f (g1836 x) @[simp] axiom s1837 (x : Prop) : f (g1838 x) = f (g1837 x) @[simp] axiom s1838 (x : Prop) : f (g1839 x) = f (g1838 x) @[simp] axiom s1839 (x : Prop) : f (g1840 x) = f (g1839 x) @[simp] axiom s1840 (x : Prop) : f (g1841 x) = f (g1840 x) @[simp] axiom s1841 (x : Prop) : f (g1842 x) = f (g1841 x) @[simp] axiom s1842 (x : Prop) : f (g1843 x) = f (g1842 x) @[simp] axiom s1843 (x : Prop) : f (g1844 x) = f (g1843 x) @[simp] axiom s1844 (x : Prop) : f (g1845 x) = f (g1844 x) @[simp] axiom s1845 (x : Prop) : f (g1846 x) = f (g1845 x) @[simp] axiom s1846 (x : Prop) : f (g1847 x) = f (g1846 x) @[simp] axiom s1847 (x : Prop) : f (g1848 x) = f (g1847 x) @[simp] axiom s1848 (x : Prop) : f (g1849 x) = f (g1848 x) @[simp] axiom s1849 (x : Prop) : f (g1850 x) = f (g1849 x) @[simp] axiom s1850 (x : Prop) : f (g1851 x) = f (g1850 x) @[simp] axiom s1851 (x : Prop) : f (g1852 x) = f (g1851 x) @[simp] axiom s1852 (x : Prop) : f (g1853 x) = f (g1852 x) @[simp] axiom s1853 (x : Prop) : f (g1854 x) = f (g1853 x) @[simp] axiom s1854 (x : Prop) : f (g1855 x) = f (g1854 x) @[simp] axiom s1855 (x : Prop) : f (g1856 x) = f (g1855 x) @[simp] axiom s1856 (x : Prop) : f (g1857 x) = f (g1856 x) @[simp] axiom s1857 (x : Prop) : f (g1858 x) = f (g1857 x) @[simp] axiom s1858 (x : Prop) : f (g1859 x) = f (g1858 x) @[simp] axiom s1859 (x : Prop) : f (g1860 x) = f (g1859 x) @[simp] axiom s1860 (x : Prop) : f (g1861 x) = f (g1860 x) @[simp] axiom s1861 (x : Prop) : f (g1862 x) = f (g1861 x) @[simp] axiom s1862 (x : Prop) : f (g1863 x) = f (g1862 x) @[simp] axiom s1863 (x : Prop) : f (g1864 x) = f (g1863 x) @[simp] axiom s1864 (x : Prop) : f (g1865 x) = f (g1864 x) @[simp] axiom s1865 (x : Prop) : f (g1866 x) = f (g1865 x) @[simp] axiom s1866 (x : Prop) : f (g1867 x) = f (g1866 x) @[simp] axiom s1867 (x : Prop) : f (g1868 x) = f (g1867 x) @[simp] axiom s1868 (x : Prop) : f (g1869 x) = f (g1868 x) @[simp] axiom s1869 (x : Prop) : f (g1870 x) = f (g1869 x) @[simp] axiom s1870 (x : Prop) : f (g1871 x) = f (g1870 x) @[simp] axiom s1871 (x : Prop) : f (g1872 x) = f (g1871 x) @[simp] axiom s1872 (x : Prop) : f (g1873 x) = f (g1872 x) @[simp] axiom s1873 (x : Prop) : f (g1874 x) = f (g1873 x) @[simp] axiom s1874 (x : Prop) : f (g1875 x) = f (g1874 x) @[simp] axiom s1875 (x : Prop) : f (g1876 x) = f (g1875 x) @[simp] axiom s1876 (x : Prop) : f (g1877 x) = f (g1876 x) @[simp] axiom s1877 (x : Prop) : f (g1878 x) = f (g1877 x) @[simp] axiom s1878 (x : Prop) : f (g1879 x) = f (g1878 x) @[simp] axiom s1879 (x : Prop) : f (g1880 x) = f (g1879 x) @[simp] axiom s1880 (x : Prop) : f (g1881 x) = f (g1880 x) @[simp] axiom s1881 (x : Prop) : f (g1882 x) = f (g1881 x) @[simp] axiom s1882 (x : Prop) : f (g1883 x) = f (g1882 x) @[simp] axiom s1883 (x : Prop) : f (g1884 x) = f (g1883 x) @[simp] axiom s1884 (x : Prop) : f (g1885 x) = f (g1884 x) @[simp] axiom s1885 (x : Prop) : f (g1886 x) = f (g1885 x) @[simp] axiom s1886 (x : Prop) : f (g1887 x) = f (g1886 x) @[simp] axiom s1887 (x : Prop) : f (g1888 x) = f (g1887 x) @[simp] axiom s1888 (x : Prop) : f (g1889 x) = f (g1888 x) @[simp] axiom s1889 (x : Prop) : f (g1890 x) = f (g1889 x) @[simp] axiom s1890 (x : Prop) : f (g1891 x) = f (g1890 x) @[simp] axiom s1891 (x : Prop) : f (g1892 x) = f (g1891 x) @[simp] axiom s1892 (x : Prop) : f (g1893 x) = f (g1892 x) @[simp] axiom s1893 (x : Prop) : f (g1894 x) = f (g1893 x) @[simp] axiom s1894 (x : Prop) : f (g1895 x) = f (g1894 x) @[simp] axiom s1895 (x : Prop) : f (g1896 x) = f (g1895 x) @[simp] axiom s1896 (x : Prop) : f (g1897 x) = f (g1896 x) @[simp] axiom s1897 (x : Prop) : f (g1898 x) = f (g1897 x) @[simp] axiom s1898 (x : Prop) : f (g1899 x) = f (g1898 x) @[simp] axiom s1899 (x : Prop) : f (g1900 x) = f (g1899 x) @[simp] axiom s1900 (x : Prop) : f (g1901 x) = f (g1900 x) @[simp] axiom s1901 (x : Prop) : f (g1902 x) = f (g1901 x) @[simp] axiom s1902 (x : Prop) : f (g1903 x) = f (g1902 x) @[simp] axiom s1903 (x : Prop) : f (g1904 x) = f (g1903 x) @[simp] axiom s1904 (x : Prop) : f (g1905 x) = f (g1904 x) @[simp] axiom s1905 (x : Prop) : f (g1906 x) = f (g1905 x) @[simp] axiom s1906 (x : Prop) : f (g1907 x) = f (g1906 x) @[simp] axiom s1907 (x : Prop) : f (g1908 x) = f (g1907 x) @[simp] axiom s1908 (x : Prop) : f (g1909 x) = f (g1908 x) @[simp] axiom s1909 (x : Prop) : f (g1910 x) = f (g1909 x) @[simp] axiom s1910 (x : Prop) : f (g1911 x) = f (g1910 x) @[simp] axiom s1911 (x : Prop) : f (g1912 x) = f (g1911 x) @[simp] axiom s1912 (x : Prop) : f (g1913 x) = f (g1912 x) @[simp] axiom s1913 (x : Prop) : f (g1914 x) = f (g1913 x) @[simp] axiom s1914 (x : Prop) : f (g1915 x) = f (g1914 x) @[simp] axiom s1915 (x : Prop) : f (g1916 x) = f (g1915 x) @[simp] axiom s1916 (x : Prop) : f (g1917 x) = f (g1916 x) @[simp] axiom s1917 (x : Prop) : f (g1918 x) = f (g1917 x) @[simp] axiom s1918 (x : Prop) : f (g1919 x) = f (g1918 x) @[simp] axiom s1919 (x : Prop) : f (g1920 x) = f (g1919 x) @[simp] axiom s1920 (x : Prop) : f (g1921 x) = f (g1920 x) @[simp] axiom s1921 (x : Prop) : f (g1922 x) = f (g1921 x) @[simp] axiom s1922 (x : Prop) : f (g1923 x) = f (g1922 x) @[simp] axiom s1923 (x : Prop) : f (g1924 x) = f (g1923 x) @[simp] axiom s1924 (x : Prop) : f (g1925 x) = f (g1924 x) @[simp] axiom s1925 (x : Prop) : f (g1926 x) = f (g1925 x) @[simp] axiom s1926 (x : Prop) : f (g1927 x) = f (g1926 x) @[simp] axiom s1927 (x : Prop) : f (g1928 x) = f (g1927 x) @[simp] axiom s1928 (x : Prop) : f (g1929 x) = f (g1928 x) @[simp] axiom s1929 (x : Prop) : f (g1930 x) = f (g1929 x) @[simp] axiom s1930 (x : Prop) : f (g1931 x) = f (g1930 x) @[simp] axiom s1931 (x : Prop) : f (g1932 x) = f (g1931 x) @[simp] axiom s1932 (x : Prop) : f (g1933 x) = f (g1932 x) @[simp] axiom s1933 (x : Prop) : f (g1934 x) = f (g1933 x) @[simp] axiom s1934 (x : Prop) : f (g1935 x) = f (g1934 x) @[simp] axiom s1935 (x : Prop) : f (g1936 x) = f (g1935 x) @[simp] axiom s1936 (x : Prop) : f (g1937 x) = f (g1936 x) @[simp] axiom s1937 (x : Prop) : f (g1938 x) = f (g1937 x) @[simp] axiom s1938 (x : Prop) : f (g1939 x) = f (g1938 x) @[simp] axiom s1939 (x : Prop) : f (g1940 x) = f (g1939 x) @[simp] axiom s1940 (x : Prop) : f (g1941 x) = f (g1940 x) @[simp] axiom s1941 (x : Prop) : f (g1942 x) = f (g1941 x) @[simp] axiom s1942 (x : Prop) : f (g1943 x) = f (g1942 x) @[simp] axiom s1943 (x : Prop) : f (g1944 x) = f (g1943 x) @[simp] axiom s1944 (x : Prop) : f (g1945 x) = f (g1944 x) @[simp] axiom s1945 (x : Prop) : f (g1946 x) = f (g1945 x) @[simp] axiom s1946 (x : Prop) : f (g1947 x) = f (g1946 x) @[simp] axiom s1947 (x : Prop) : f (g1948 x) = f (g1947 x) @[simp] axiom s1948 (x : Prop) : f (g1949 x) = f (g1948 x) @[simp] axiom s1949 (x : Prop) : f (g1950 x) = f (g1949 x) @[simp] axiom s1950 (x : Prop) : f (g1951 x) = f (g1950 x) @[simp] axiom s1951 (x : Prop) : f (g1952 x) = f (g1951 x) @[simp] axiom s1952 (x : Prop) : f (g1953 x) = f (g1952 x) @[simp] axiom s1953 (x : Prop) : f (g1954 x) = f (g1953 x) @[simp] axiom s1954 (x : Prop) : f (g1955 x) = f (g1954 x) @[simp] axiom s1955 (x : Prop) : f (g1956 x) = f (g1955 x) @[simp] axiom s1956 (x : Prop) : f (g1957 x) = f (g1956 x) @[simp] axiom s1957 (x : Prop) : f (g1958 x) = f (g1957 x) @[simp] axiom s1958 (x : Prop) : f (g1959 x) = f (g1958 x) @[simp] axiom s1959 (x : Prop) : f (g1960 x) = f (g1959 x) @[simp] axiom s1960 (x : Prop) : f (g1961 x) = f (g1960 x) @[simp] axiom s1961 (x : Prop) : f (g1962 x) = f (g1961 x) @[simp] axiom s1962 (x : Prop) : f (g1963 x) = f (g1962 x) @[simp] axiom s1963 (x : Prop) : f (g1964 x) = f (g1963 x) @[simp] axiom s1964 (x : Prop) : f (g1965 x) = f (g1964 x) @[simp] axiom s1965 (x : Prop) : f (g1966 x) = f (g1965 x) @[simp] axiom s1966 (x : Prop) : f (g1967 x) = f (g1966 x) @[simp] axiom s1967 (x : Prop) : f (g1968 x) = f (g1967 x) @[simp] axiom s1968 (x : Prop) : f (g1969 x) = f (g1968 x) @[simp] axiom s1969 (x : Prop) : f (g1970 x) = f (g1969 x) @[simp] axiom s1970 (x : Prop) : f (g1971 x) = f (g1970 x) @[simp] axiom s1971 (x : Prop) : f (g1972 x) = f (g1971 x) @[simp] axiom s1972 (x : Prop) : f (g1973 x) = f (g1972 x) @[simp] axiom s1973 (x : Prop) : f (g1974 x) = f (g1973 x) @[simp] axiom s1974 (x : Prop) : f (g1975 x) = f (g1974 x) @[simp] axiom s1975 (x : Prop) : f (g1976 x) = f (g1975 x) @[simp] axiom s1976 (x : Prop) : f (g1977 x) = f (g1976 x) @[simp] axiom s1977 (x : Prop) : f (g1978 x) = f (g1977 x) @[simp] axiom s1978 (x : Prop) : f (g1979 x) = f (g1978 x) @[simp] axiom s1979 (x : Prop) : f (g1980 x) = f (g1979 x) @[simp] axiom s1980 (x : Prop) : f (g1981 x) = f (g1980 x) @[simp] axiom s1981 (x : Prop) : f (g1982 x) = f (g1981 x) @[simp] axiom s1982 (x : Prop) : f (g1983 x) = f (g1982 x) @[simp] axiom s1983 (x : Prop) : f (g1984 x) = f (g1983 x) @[simp] axiom s1984 (x : Prop) : f (g1985 x) = f (g1984 x) @[simp] axiom s1985 (x : Prop) : f (g1986 x) = f (g1985 x) @[simp] axiom s1986 (x : Prop) : f (g1987 x) = f (g1986 x) @[simp] axiom s1987 (x : Prop) : f (g1988 x) = f (g1987 x) @[simp] axiom s1988 (x : Prop) : f (g1989 x) = f (g1988 x) @[simp] axiom s1989 (x : Prop) : f (g1990 x) = f (g1989 x) @[simp] axiom s1990 (x : Prop) : f (g1991 x) = f (g1990 x) @[simp] axiom s1991 (x : Prop) : f (g1992 x) = f (g1991 x) @[simp] axiom s1992 (x : Prop) : f (g1993 x) = f (g1992 x) @[simp] axiom s1993 (x : Prop) : f (g1994 x) = f (g1993 x) @[simp] axiom s1994 (x : Prop) : f (g1995 x) = f (g1994 x) @[simp] axiom s1995 (x : Prop) : f (g1996 x) = f (g1995 x) @[simp] axiom s1996 (x : Prop) : f (g1997 x) = f (g1996 x) @[simp] axiom s1997 (x : Prop) : f (g1998 x) = f (g1997 x) @[simp] axiom s1998 (x : Prop) : f (g1999 x) = f (g1998 x)
b2e7a10fd12e89f41000e5b0cf97e20305051fec
82b86ba2ae0d5aed0f01f49c46db5afec0eb2bd7
/src/Init/Data/Array/BinSearch.lean
5172a282f7c3ee34b3efa48ddc93c4ae585d04a1
[ "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
2,754
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.Array.Basic universes u v -- TODO: CLEANUP namespace Array -- TODO: remove the [Inhabited α] parameters as soon as we have the tactic framework for automating proof generation and using Array.fget -- TODO: remove `partial` using well-founded recursion @[specialize] partial def binSearchAux {α : Type u} {β : Type v} [Inhabited α] [Inhabited β] (lt : α → α → Bool) (found : Option α → β) (as : Array α) (k : α) : Nat → Nat → β | lo, hi => if lo <= hi then let m := (lo + hi)/2; let a := as.get! m; if lt a k then binSearchAux lt found as k (m+1) hi else if lt k a then if m == 0 then found none else binSearchAux lt found as k lo (m-1) else found (some a) else found none @[inline] def binSearch {α : Type} [Inhabited α] (as : Array α) (k : α) (lt : α → α → Bool) (lo := 0) (hi := as.size - 1) : Option α := binSearchAux lt id as k lo hi @[inline] def binSearchContains {α : Type} [Inhabited α] (as : Array α) (k : α) (lt : α → α → Bool) (lo := 0) (hi := as.size - 1) : Bool := binSearchAux lt Option.isSome as k lo hi @[specialize] private partial def binInsertAux {α : Type u} {m : Type u → Type v} [Monad m] [Inhabited α] (lt : α → α → Bool) (merge : α → m α) (add : Unit → m α) (as : Array α) (k : α) : Nat → Nat → m (Array α) | lo, hi => -- as[lo] < k < as[hi] let mid := (lo + hi)/2; let midVal := as.get! mid; if lt midVal k then if mid == lo then do let v ← add (); pure $ as.insertAt (lo+1) v else binInsertAux lt merge add as k mid hi else if lt k midVal then binInsertAux lt merge add as k lo mid else do as.modifyM mid $ fun v => merge v @[specialize] partial def binInsertM {α : Type u} {m : Type u → Type v} [Monad m] [Inhabited α] (lt : α → α → Bool) (merge : α → m α) (add : Unit → m α) (as : Array α) (k : α) : m (Array α) := if as.isEmpty then do let v ← add (); pure $ as.push v else if lt k (as.get! 0) then do let v ← add (); pure $ as.insertAt 0 v else if !lt (as.get! 0) k then as.modifyM 0 $ merge else if lt as.back k then do let v ← add (); pure $ as.push v else if !lt k as.back then as.modifyM (as.size - 1) $ merge else binInsertAux lt merge add as k 0 (as.size - 1) @[inline] def binInsert {α : Type u} [Inhabited α] (lt : α → α → Bool) (as : Array α) (k : α) : Array α := Id.run $ binInsertM lt (fun _ => k) (fun _ => k) as k end Array
c9d79b08296ef4a6f36e4e425fffca1470bab734
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/data/list/rotate.lean
6bb883e0b74062bd8a20afb2a57833e3a9b4122b
[ "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,675
lean
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yakov Pechersky -/ import data.list.perm import data.list.range /-! # List rotation This file proves basic results about `list.rotate`, the list rotation. ## Main declarations * `is_rotated l₁ l₂`: States that `l₁` is a rotated version of `l₂`. * `cyclic_permutations l`: The list of all cyclic permutants of `l`, up to the length of `l`. ## Tags rotated, rotation, permutation, cycle -/ universe u variables {α : Type u} open nat namespace list lemma rotate_mod (l : list α) (n : ℕ) : l.rotate (n % l.length) = l.rotate n := by simp [rotate] @[simp] lemma rotate_nil (n : ℕ) : ([] : list α).rotate n = [] := by cases n; simp [rotate] @[simp] lemma rotate_zero (l : list α) : l.rotate 0 = l := by simp [rotate] @[simp] lemma rotate'_nil (n : ℕ) : ([] : list α).rotate' n = [] := by cases n; refl @[simp] lemma rotate'_zero (l : list α) : l.rotate' 0 = l := by cases l; refl lemma rotate'_cons_succ (l : list α) (a : α) (n : ℕ) : (a :: l : list α).rotate' n.succ = (l ++ [a]).rotate' n := by simp [rotate'] @[simp] lemma length_rotate' : ∀ (l : list α) (n : ℕ), (l.rotate' n).length = l.length | [] n := rfl | (a::l) 0 := rfl | (a::l) (n+1) := by rw [list.rotate', length_rotate' (l ++ [a]) n]; simp lemma rotate'_eq_drop_append_take : ∀ {l : list α} {n : ℕ}, n ≤ l.length → l.rotate' n = l.drop n ++ l.take n | [] n h := by simp [drop_append_of_le_length h] | l 0 h := by simp [take_append_of_le_length h] | (a::l) (n+1) h := have hnl : n ≤ l.length, from le_of_succ_le_succ h, have hnl' : n ≤ (l ++ [a]).length, by rw [length_append, length_cons, list.length, zero_add]; exact (le_of_succ_le h), by rw [rotate'_cons_succ, rotate'_eq_drop_append_take hnl', drop, take, drop_append_of_le_length hnl, take_append_of_le_length hnl]; simp lemma rotate'_rotate' : ∀ (l : list α) (n m : ℕ), (l.rotate' n).rotate' m = l.rotate' (n + m) | (a::l) 0 m := by simp | [] n m := by simp | (a::l) (n+1) m := by rw [rotate'_cons_succ, rotate'_rotate', add_right_comm, rotate'_cons_succ] @[simp] lemma rotate'_length (l : list α) : rotate' l l.length = l := by rw rotate'_eq_drop_append_take le_rfl; simp @[simp] lemma rotate'_length_mul (l : list α) : ∀ n : ℕ, l.rotate' (l.length * n) = l | 0 := by simp | (n+1) := calc l.rotate' (l.length * (n + 1)) = (l.rotate' (l.length * n)).rotate' (l.rotate' (l.length * n)).length : by simp [-rotate'_length, nat.mul_succ, rotate'_rotate'] ... = l : by rw [rotate'_length, rotate'_length_mul] lemma rotate'_mod (l : list α) (n : ℕ) : l.rotate' (n % l.length) = l.rotate' n := calc l.rotate' (n % l.length) = (l.rotate' (n % l.length)).rotate' ((l.rotate' (n % l.length)).length * (n / l.length)) : by rw rotate'_length_mul ... = l.rotate' n : by rw [rotate'_rotate', length_rotate', nat.mod_add_div] lemma rotate_eq_rotate' (l : list α) (n : ℕ) : l.rotate n = l.rotate' n := if h : l.length = 0 then by simp [length_eq_zero, *] at * else by rw [← rotate'_mod, rotate'_eq_drop_append_take (le_of_lt (nat.mod_lt _ (nat.pos_of_ne_zero h)))]; simp [rotate] lemma rotate_cons_succ (l : list α) (a : α) (n : ℕ) : (a :: l : list α).rotate n.succ = (l ++ [a]).rotate n := by rw [rotate_eq_rotate', rotate_eq_rotate', rotate'_cons_succ] @[simp] lemma mem_rotate : ∀ {l : list α} {a : α} {n : ℕ}, a ∈ l.rotate n ↔ a ∈ l | [] _ n := by simp | (a::l) _ 0 := by simp | (a::l) _ (n+1) := by simp [rotate_cons_succ, mem_rotate, or.comm] @[simp] lemma length_rotate (l : list α) (n : ℕ) : (l.rotate n).length = l.length := by rw [rotate_eq_rotate', length_rotate'] lemma rotate_eq_drop_append_take {l : list α} {n : ℕ} : n ≤ l.length → l.rotate n = l.drop n ++ l.take n := by rw rotate_eq_rotate'; exact rotate'_eq_drop_append_take lemma rotate_eq_drop_append_take_mod {l : list α} {n : ℕ} : l.rotate n = l.drop (n % l.length) ++ l.take (n % l.length) := begin cases l.length.zero_le.eq_or_lt with hl hl, { simp [eq_nil_of_length_eq_zero hl.symm ] }, rw [←rotate_eq_drop_append_take (n.mod_lt hl).le, rotate_mod] end @[simp] lemma rotate_append_length_eq (l l' : list α) : (l ++ l').rotate l.length = l' ++ l := begin rw rotate_eq_rotate', induction l generalizing l', { simp, }, { simp [rotate', l_ih] }, end lemma rotate_rotate (l : list α) (n m : ℕ) : (l.rotate n).rotate m = l.rotate (n + m) := by rw [rotate_eq_rotate', rotate_eq_rotate', rotate_eq_rotate', rotate'_rotate'] @[simp] lemma rotate_length (l : list α) : rotate l l.length = l := by rw [rotate_eq_rotate', rotate'_length] @[simp] lemma rotate_length_mul (l : list α) (n : ℕ) : l.rotate (l.length * n) = l := by rw [rotate_eq_rotate', rotate'_length_mul] lemma prod_rotate_eq_one_of_prod_eq_one [group α] : ∀ {l : list α} (hl : l.prod = 1) (n : ℕ), (l.rotate n).prod = 1 | [] _ _ := by simp | (a::l) hl n := have n % list.length (a :: l) ≤ list.length (a :: l), from le_of_lt (nat.mod_lt _ dec_trivial), by rw ← list.take_append_drop (n % list.length (a :: l)) (a :: l) at hl; rw [← rotate_mod, rotate_eq_drop_append_take this, list.prod_append, mul_eq_one_iff_inv_eq, ← one_mul (list.prod _)⁻¹, ← hl, list.prod_append, mul_assoc, mul_inv_self, mul_one] lemma rotate_perm (l : list α) (n : ℕ) : l.rotate n ~ l := begin rw rotate_eq_rotate', induction n with n hn generalizing l, { simp }, { cases l with hd tl, { simp }, { rw rotate'_cons_succ, exact (hn _).trans (perm_append_singleton _ _) } } end @[simp] lemma nodup_rotate {l : list α} {n : ℕ} : nodup (l.rotate n) ↔ nodup l := (rotate_perm l n).nodup_iff @[simp] lemma rotate_eq_nil_iff {l : list α} {n : ℕ} : l.rotate n = [] ↔ l = [] := begin induction n with n hn generalizing l, { simp }, { cases l with hd tl, { simp }, { simp [rotate_cons_succ, hn] } } end @[simp] lemma nil_eq_rotate_iff {l : list α} {n : ℕ} : [] = l.rotate n ↔ [] = l := by rw [eq_comm, rotate_eq_nil_iff, eq_comm] @[simp] lemma rotate_singleton (x : α) (n : ℕ) : [x].rotate n = [x] := begin induction n with n hn, { simp }, { rwa [rotate_cons_succ] } end @[simp] lemma rotate_eq_singleton_iff {l : list α} {n : ℕ} {x : α} : l.rotate n = [x] ↔ l = [x] := begin induction n with n hn generalizing l, { simp }, { cases l with hd tl, { simp }, { simp [rotate_cons_succ, hn, append_eq_cons_iff, and_comm] } } end @[simp] lemma singleton_eq_rotate_iff {l : list α} {n : ℕ} {x : α} : [x] = l.rotate n ↔ [x] = l := by rw [eq_comm, rotate_eq_singleton_iff, eq_comm] lemma zip_with_rotate_distrib {α β γ : Type*} (f : α → β → γ) (l : list α) (l' : list β) (n : ℕ) (h : l.length = l'.length) : (zip_with f l l').rotate n = zip_with f (l.rotate n) (l'.rotate n) := begin rw [rotate_eq_drop_append_take_mod, rotate_eq_drop_append_take_mod, rotate_eq_drop_append_take_mod, h, zip_with_append, ←zip_with_distrib_drop, ←zip_with_distrib_take, list.length_zip_with, h, min_self], rw [length_drop, length_drop, h] end local attribute [simp] rotate_cons_succ @[simp] lemma zip_with_rotate_one {β : Type*} (f : α → α → β) (x y : α) (l : list α) : zip_with f (x :: y :: l) ((x :: y :: l).rotate 1) = f x y :: zip_with f (y :: l) (l ++ [x]) := by simp lemma nth_le_rotate_one (l : list α) (k : ℕ) (hk : k < (l.rotate 1).length) : (l.rotate 1).nth_le k hk = l.nth_le ((k + 1) % l.length) (mod_lt _ (length_rotate l 1 ▸ k.zero_le.trans_lt hk)) := begin cases l with hd tl, { simp }, { have : k ≤ tl.length, { refine nat.le_of_lt_succ _, simpa using hk }, rcases this.eq_or_lt with rfl|hk', { simp [nth_le_append_right le_rfl] }, { simpa [nth_le_append _ hk', length_cons, nat.mod_eq_of_lt (nat.succ_lt_succ hk')] } } end lemma nth_le_rotate (l : list α) (n k : ℕ) (hk : k < (l.rotate n).length) : (l.rotate n).nth_le k hk = l.nth_le ((k + n) % l.length) (mod_lt _ (length_rotate l n ▸ k.zero_le.trans_lt hk)) := begin induction n with n hn generalizing l k, { have hk' : k < l.length := by simpa using hk, simp [nat.mod_eq_of_lt hk'] }, { simp [nat.succ_eq_add_one, ←rotate_rotate, nth_le_rotate_one, hn l, add_comm, add_left_comm] } end /-- A variant of `nth_le_rotate` useful for rewrites. -/ lemma nth_le_rotate' (l : list α) (n k : ℕ) (hk : k < l.length) : (l.rotate n).nth_le ((l.length - n % l.length + k) % l.length) ((nat.mod_lt _ (k.zero_le.trans_lt hk)).trans_le (length_rotate _ _).ge) = l.nth_le k hk := begin rw nth_le_rotate, congr, set m := l.length, rw [mod_add_mod, add_assoc, add_left_comm, add_comm, add_mod, add_mod _ n], cases (n % m).zero_le.eq_or_lt with hn hn, { simpa [←hn] using nat.mod_eq_of_lt hk }, { have mpos : 0 < m := k.zero_le.trans_lt hk, have hm : m - n % m < m := tsub_lt_self mpos hn, have hn' : n % m < m := nat.mod_lt _ mpos, simpa [mod_eq_of_lt hm, tsub_add_cancel_of_le hn'.le] using nat.mod_eq_of_lt hk } end lemma rotate_injective (n : ℕ) : function.injective (λ l : list α, l.rotate n) := begin rintros l l' (h : l.rotate n = l'.rotate n), have hle : l.length = l'.length := (l.length_rotate n).symm.trans (h.symm ▸ l'.length_rotate n), rw [rotate_eq_drop_append_take_mod, rotate_eq_drop_append_take_mod] at h, obtain ⟨hd, ht⟩ := append_inj h _, { rw [←take_append_drop _ l, ht, hd, take_append_drop] }, { rw [length_drop, length_drop, hle] } end -- possibly easier to find in doc-gen, otherwise not that useful. lemma rotate_eq_rotate {l l' : list α} {n : ℕ} : l.rotate n = l'.rotate n ↔ l = l' := (rotate_injective n).eq_iff lemma rotate_eq_iff {l l' : list α} {n : ℕ} : l.rotate n = l' ↔ l = l'.rotate (l'.length - n % l'.length) := begin rw [←@rotate_eq_rotate _ l _ n, rotate_rotate, ←rotate_mod l', add_mod], cases l'.length.zero_le.eq_or_lt with hl hl, { rw [eq_nil_of_length_eq_zero hl.symm, rotate_nil, rotate_eq_nil_iff] }, { cases (nat.zero_le (n % l'.length)).eq_or_lt with hn hn, { simp [←hn] }, { rw [mod_eq_of_lt (tsub_lt_self hl hn), tsub_add_cancel_of_le, mod_self, rotate_zero], exact (nat.mod_lt _ hl).le } } end lemma reverse_rotate (l : list α) (n : ℕ) : (l.rotate n).reverse = l.reverse.rotate (l.length - (n % l.length)) := begin rw [←length_reverse l, ←rotate_eq_iff], induction n with n hn generalizing l, { simp }, { cases l with hd tl, { simp }, { rw [rotate_cons_succ, nat.succ_eq_add_one, ←rotate_rotate, hn], simp } } end lemma rotate_reverse (l : list α) (n : ℕ) : l.reverse.rotate n = (l.rotate (l.length - (n % l.length))).reverse := begin rw [←reverse_reverse l], simp_rw [reverse_rotate, reverse_reverse, rotate_eq_iff, rotate_rotate, length_rotate, length_reverse], rw [←length_reverse l], set k := n % l.reverse.length with hk, cases hk' : k with k', { simp [-length_reverse, ←rotate_rotate] }, { cases l with x l, { simp }, { have : k'.succ < (x :: l).length, { simp [←hk', hk, nat.mod_lt] }, rw [nat.mod_eq_of_lt, tsub_add_cancel_of_le, rotate_length], { exact tsub_le_self }, { exact tsub_lt_self (by simp) nat.succ_pos' } } } end lemma map_rotate {β : Type*} (f : α → β) (l : list α) (n : ℕ) : map f (l.rotate n) = (map f l).rotate n := begin induction n with n hn IH generalizing l, { simp }, { cases l with hd tl, { simp }, { simp [hn] } } end theorem nodup.rotate_eq_self_iff {l : list α} (hl : l.nodup) {n : ℕ} : l.rotate n = l ↔ n % l.length = 0 ∨ l = [] := begin split, { intro h, cases l.length.zero_le.eq_or_lt with hl' hl', { simp [←length_eq_zero, ←hl'] }, left, rw nodup_iff_nth_le_inj at hl, refine hl _ _ (mod_lt _ hl') hl' _, rw ←nth_le_rotate' _ n, simp_rw [h, tsub_add_cancel_of_le (mod_lt _ hl').le, mod_self] }, { rintro (h|h), { rw [←rotate_mod, h], exact rotate_zero l }, { simp [h] } } end lemma nodup.rotate_congr {l : list α} (hl : l.nodup) (hn : l ≠ []) (i j : ℕ) (h : l.rotate i = l.rotate j) : i % l.length = j % l.length := begin have hi : i % l.length < l.length := mod_lt _ (length_pos_of_ne_nil hn), have hj : j % l.length < l.length := mod_lt _ (length_pos_of_ne_nil hn), refine (nodup_iff_nth_le_inj.mp hl) _ _ hi hj _, rw [←nth_le_rotate' l i, ←nth_le_rotate' l j], simp [tsub_add_cancel_of_le, hi.le, hj.le, h] end section is_rotated variables (l l' : list α) /-- `is_rotated l₁ l₂` or `l₁ ~r l₂` asserts that `l₁` and `l₂` are cyclic permutations of each other. This is defined by claiming that `∃ n, l.rotate n = l'`. -/ def is_rotated : Prop := ∃ n, l.rotate n = l' infixr ` ~r `:1000 := is_rotated variables {l l'} @[refl] lemma is_rotated.refl (l : list α) : l ~r l := ⟨0, by simp⟩ @[symm] lemma is_rotated.symm (h : l ~r l') : l' ~r l := begin obtain ⟨n, rfl⟩ := h, cases l with hd tl, { simp }, { use (hd :: tl).length * n - n, rw [rotate_rotate, add_tsub_cancel_of_le, rotate_length_mul], exact nat.le_mul_of_pos_left (by simp) } end lemma is_rotated_comm : l ~r l' ↔ l' ~r l := ⟨is_rotated.symm, is_rotated.symm⟩ @[simp] protected lemma is_rotated.forall (l : list α) (n : ℕ) : l.rotate n ~r l := is_rotated.symm ⟨n, rfl⟩ @[trans] lemma is_rotated.trans {l'' : list α} (h : l ~r l') (h' : l' ~r l'') : l ~r l'' := begin obtain ⟨n, rfl⟩ := h, obtain ⟨m, rfl⟩ := h', rw rotate_rotate, use (n + m) end lemma is_rotated.eqv : equivalence (@is_rotated α) := mk_equivalence _ is_rotated.refl (λ _ _, is_rotated.symm) (λ _ _ _, is_rotated.trans) /-- The relation `list.is_rotated l l'` forms a `setoid` of cycles. -/ def is_rotated.setoid (α : Type*) : setoid (list α) := { r := is_rotated, iseqv := is_rotated.eqv } lemma is_rotated.perm (h : l ~r l') : l ~ l' := exists.elim h (λ _ hl, hl ▸ (rotate_perm _ _).symm) lemma is_rotated.nodup_iff (h : l ~r l') : nodup l ↔ nodup l' := h.perm.nodup_iff lemma is_rotated.mem_iff (h : l ~r l') {a : α} : a ∈ l ↔ a ∈ l' := h.perm.mem_iff @[simp] lemma is_rotated_nil_iff : l ~r [] ↔ l = [] := ⟨λ ⟨n, hn⟩, by simpa using hn, λ h, h ▸ by refl⟩ @[simp] lemma is_rotated_nil_iff' : [] ~r l ↔ [] = l := by rw [is_rotated_comm, is_rotated_nil_iff, eq_comm] @[simp] lemma is_rotated_singleton_iff {x : α} : l ~r [x] ↔ l = [x] := ⟨λ ⟨n, hn⟩, by simpa using hn, λ h, h ▸ by refl⟩ @[simp] lemma is_rotated_singleton_iff' {x : α} : [x] ~r l ↔ [x] = l := by rw [is_rotated_comm, is_rotated_singleton_iff, eq_comm] lemma is_rotated_concat (hd : α) (tl : list α) : (tl ++ [hd]) ~r (hd :: tl) := is_rotated.symm ⟨1, by simp⟩ lemma is_rotated_append : (l ++ l') ~r (l' ++ l) := ⟨l.length, by simp⟩ lemma is_rotated.reverse (h : l ~r l') : l.reverse ~r l'.reverse := begin obtain ⟨n, rfl⟩ := h, exact ⟨_, (reverse_rotate _ _).symm⟩ end lemma is_rotated_reverse_comm_iff : l.reverse ~r l' ↔ l ~r l'.reverse := begin split; { intro h, simpa using h.reverse } end @[simp] lemma is_rotated_reverse_iff : l.reverse ~r l'.reverse ↔ l ~r l' := by simp [is_rotated_reverse_comm_iff] lemma is_rotated_iff_mod : l ~r l' ↔ ∃ n ≤ l.length, l.rotate n = l' := begin refine ⟨λ h, _, λ ⟨n, _, h⟩, ⟨n, h⟩⟩, obtain ⟨n, rfl⟩ := h, cases l with hd tl, { simp }, { refine ⟨n % (hd :: tl).length, _, rotate_mod _ _⟩, refine (nat.mod_lt _ _).le, simp } end lemma is_rotated_iff_mem_map_range : l ~r l' ↔ l' ∈ (list.range (l.length + 1)).map l.rotate := begin simp_rw [mem_map, mem_range, is_rotated_iff_mod], exact ⟨λ ⟨n, hn, h⟩, ⟨n, nat.lt_succ_of_le hn, h⟩, λ ⟨n, hn, h⟩, ⟨n, nat.le_of_lt_succ hn, h⟩⟩ end @[congr] theorem is_rotated.map {β : Type*} {l₁ l₂ : list α} (h : l₁ ~r l₂) (f : α → β) : map f l₁ ~r map f l₂ := begin obtain ⟨n, rfl⟩ := h, rw map_rotate, use n end /-- List of all cyclic permutations of `l`. The `cyclic_permutations` of a nonempty list `l` will always contain `list.length l` elements. This implies that under certain conditions, there are duplicates in `list.cyclic_permutations l`. The `n`th entry is equal to `l.rotate n`, proven in `list.nth_le_cyclic_permutations`. The proof that every cyclic permutant of `l` is in the list is `list.mem_cyclic_permutations_iff`. cyclic_permutations [1, 2, 3, 2, 4] = [[1, 2, 3, 2, 4], [2, 3, 2, 4, 1], [3, 2, 4, 1, 2], [2, 4, 1, 2, 3], [4, 1, 2, 3, 2]] -/ def cyclic_permutations : list α → list (list α) | [] := [[]] | l@(_ :: _) := init (zip_with (++) (tails l) (inits l)) @[simp] lemma cyclic_permutations_nil : cyclic_permutations ([] : list α) = [[]] := rfl lemma cyclic_permutations_cons (x : α) (l : list α) : cyclic_permutations (x :: l) = init (zip_with (++) (tails (x :: l)) (inits (x :: l))) := rfl lemma cyclic_permutations_of_ne_nil (l : list α) (h : l ≠ []) : cyclic_permutations l = init (zip_with (++) (tails l) (inits l)) := begin obtain ⟨hd, tl, rfl⟩ := exists_cons_of_ne_nil h, exact cyclic_permutations_cons _ _, end lemma length_cyclic_permutations_cons (x : α) (l : list α) : length (cyclic_permutations (x :: l)) = length l + 1 := by simp [cyclic_permutations_of_ne_nil] @[simp] lemma length_cyclic_permutations_of_ne_nil (l : list α) (h : l ≠ []) : length (cyclic_permutations l) = length l := by simp [cyclic_permutations_of_ne_nil _ h] @[simp] lemma nth_le_cyclic_permutations (l : list α) (n : ℕ) (hn : n < length (cyclic_permutations l)) : nth_le (cyclic_permutations l) n hn = l.rotate n := begin obtain rfl | h := eq_or_ne l [], { simp }, { rw length_cyclic_permutations_of_ne_nil _ h at hn, simp [init_eq_take, cyclic_permutations_of_ne_nil _ h, nth_le_take', rotate_eq_drop_append_take hn.le] } end lemma mem_cyclic_permutations_self (l : list α) : l ∈ cyclic_permutations l := begin cases l with x l, { simp }, { rw mem_iff_nth_le, refine ⟨0, by simp, _⟩, simp } end lemma length_mem_cyclic_permutations (l : list α) (h : l' ∈ cyclic_permutations l) : length l' = length l := begin obtain ⟨k, hk, rfl⟩ := nth_le_of_mem h, simp end @[simp] lemma mem_cyclic_permutations_iff {l l' : list α} : l ∈ cyclic_permutations l' ↔ l ~r l' := begin split, { intro h, obtain ⟨k, hk, rfl⟩ := nth_le_of_mem h, simp }, { intro h, obtain ⟨k, rfl⟩ := h.symm, rw mem_iff_nth_le, simp only [exists_prop, nth_le_cyclic_permutations], cases l' with x l, { simp }, { refine ⟨k % length (x :: l), _, rotate_mod _ _⟩, simpa using nat.mod_lt _ (zero_lt_succ _) } } end @[simp] lemma cyclic_permutations_eq_nil_iff {l : list α} : cyclic_permutations l = [[]] ↔ l = [] := begin refine ⟨λ h, _, λ h, by simp [h]⟩, rw [eq_comm, ←is_rotated_nil_iff', ←mem_cyclic_permutations_iff, h, mem_singleton] end @[simp] lemma cyclic_permutations_eq_singleton_iff {l : list α} {x : α} : cyclic_permutations l = [[x]] ↔ l = [x] := begin refine ⟨λ h, _, λ h, by simp [cyclic_permutations, h, init_eq_take]⟩, rw [eq_comm, ←is_rotated_singleton_iff', ←mem_cyclic_permutations_iff, h, mem_singleton] end /-- If a `l : list α` is `nodup l`, then all of its cyclic permutants are distinct. -/ lemma nodup.cyclic_permutations {l : list α} (hn : nodup l) : nodup (cyclic_permutations l) := begin cases l with x l, { simp }, rw nodup_iff_nth_le_inj, intros i j hi hj h, simp only [length_cyclic_permutations_cons] at hi hj, rw [←mod_eq_of_lt hi, ←mod_eq_of_lt hj, ←length_cons x l], apply hn.rotate_congr, { simp }, { simpa using h } end @[simp] lemma cyclic_permutations_rotate (l : list α) (k : ℕ) : (l.rotate k).cyclic_permutations = l.cyclic_permutations.rotate k := begin have : (l.rotate k).cyclic_permutations.length = length (l.cyclic_permutations.rotate k), { cases l, { simp }, { rw length_cyclic_permutations_of_ne_nil; simp } }, refine ext_le this (λ n hn hn', _), rw [nth_le_cyclic_permutations, nth_le_rotate, nth_le_cyclic_permutations, rotate_rotate, ←rotate_mod, add_comm], cases l; simp end lemma is_rotated.cyclic_permutations {l l' : list α} (h : l ~r l') : l.cyclic_permutations ~r l'.cyclic_permutations := begin obtain ⟨k, rfl⟩ := h, exact ⟨k, by simp⟩ end @[simp] lemma is_rotated_cyclic_permutations_iff {l l' : list α} : l.cyclic_permutations ~r l'.cyclic_permutations ↔ l ~r l' := begin by_cases hl : l = [], { simp [hl, eq_comm] }, have hl' : l.cyclic_permutations.length = l.length := length_cyclic_permutations_of_ne_nil _ hl, refine ⟨λ h, _, is_rotated.cyclic_permutations⟩, obtain ⟨k, hk⟩ := h, refine ⟨k % l.length, _⟩, have hk' : k % l.length < l.length := mod_lt _ (length_pos_of_ne_nil hl), rw [←nth_le_cyclic_permutations _ _ (hk'.trans_le hl'.ge), ←nth_le_rotate' _ k], simp [hk, hl', tsub_add_cancel_of_le hk'.le] end section decidable variables [decidable_eq α] instance is_rotated_decidable (l l' : list α) : decidable (l ~r l') := decidable_of_iff' _ is_rotated_iff_mem_map_range instance {l l' : list α} : decidable (@setoid.r _ (is_rotated.setoid α) l l') := list.is_rotated_decidable _ _ end decidable end is_rotated end list
2394f6c315f7e57c9ec127b3f17178f0df3dee2f
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/data/polynomial/algebra_map.lean
b07c832207cdf826176a1f36c422de24b596a4ac
[]
no_license
AurelienSaue/Mathlib4_auto
f538cfd0980f65a6361eadea39e6fc639e9dae14
590df64109b08190abe22358fabc3eae000943f2
refs/heads/master
1,683,906,849,776
1,622,564,669,000
1,622,564,669,000
371,723,747
0
0
null
null
null
null
UTF-8
Lean
false
false
10,356
lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.polynomial.eval import Mathlib.algebra.algebra.tower import Mathlib.PostPort universes u z u_1 u_2 u_3 v namespace Mathlib /-! # Theory of univariate polynomials We show that `polynomial A` is an R-algebra when `A` is an R-algebra. We promote `eval₂` to an algebra hom in `aeval`. -/ namespace polynomial /-- Note that this instance also provides `algebra R (polynomial R)`. -/ protected instance algebra_of_algebra {R : Type u} {A : Type z} [comm_semiring R] [semiring A] [algebra R A] : algebra R (polynomial A) := add_monoid_algebra.algebra theorem algebra_map_apply {R : Type u} {A : Type z} [comm_semiring R] [semiring A] [algebra R A] (r : R) : coe_fn (algebra_map R (polynomial A)) r = coe_fn C (coe_fn (algebra_map R A) r) := rfl /-- When we have `[comm_ring R]`, the function `C` is the same as `algebra_map R (polynomial R)`. (But note that `C` is defined when `R` is not necessarily commutative, in which case `algebra_map` is not available.) -/ theorem C_eq_algebra_map {R : Type u_1} [comm_ring R] (r : R) : coe_fn C r = coe_fn (algebra_map R (polynomial R)) r := rfl @[simp] theorem alg_hom_eval₂_algebra_map {R : Type u_1} {A : Type u_2} {B : Type u_3} [comm_ring R] [ring A] [ring B] [algebra R A] [algebra R B] (p : polynomial R) (f : alg_hom R A B) (a : A) : coe_fn f (eval₂ (algebra_map R A) a p) = eval₂ (algebra_map R B) (coe_fn f a) p := sorry @[simp] theorem eval₂_algebra_map_X {R : Type u_1} {A : Type u_2} [comm_ring R] [ring A] [algebra R A] (p : polynomial R) (f : alg_hom R (polynomial R) A) : eval₂ (algebra_map R A) (coe_fn f X) p = coe_fn f p := sorry @[simp] theorem ring_hom_eval₂_algebra_map_int {R : Type u_1} {S : Type u_2} [ring R] [ring S] (p : polynomial ℤ) (f : R →+* S) (r : R) : coe_fn f (eval₂ (algebra_map ℤ R) r p) = eval₂ (algebra_map ℤ S) (coe_fn f r) p := alg_hom_eval₂_algebra_map p (ring_hom.to_int_alg_hom f) r @[simp] theorem eval₂_algebra_map_int_X {R : Type u_1} [ring R] (p : polynomial ℤ) (f : polynomial ℤ →+* R) : eval₂ (algebra_map ℤ R) (coe_fn f X) p = coe_fn f p := sorry -- Unfortunately `f.to_int_alg_hom` doesn't work here, as typeclasses don't match up correctly. theorem eval₂_comp {R : Type u} {S : Type v} [comm_semiring R] {p : polynomial R} {q : polynomial R} [comm_semiring S] (f : R →+* S) {x : S} : eval₂ f x (comp p q) = eval₂ f (eval₂ f x q) p := sorry theorem eval_comp {R : Type u} {a : R} [comm_semiring R] {p : polynomial R} {q : polynomial R} : eval a (comp p q) = eval (eval a q) p := eval₂_comp (ring_hom.id R) protected instance comp.is_semiring_hom {R : Type u} [comm_semiring R] {p : polynomial R} : is_semiring_hom fun (q : polynomial R) => comp q p := eq.mpr (id ((fun (f f_1 : polynomial R → polynomial R) (e_3 : f = f_1) => congr_arg is_semiring_hom e_3) (fun (q : polynomial R) => comp q p) (fun (q : polynomial R) => eval₂ C p q) (funext fun (q : polynomial R) => comp.equations._eqn_1 q p))) (eval₂.is_semiring_hom C p) /-- Given a valuation `x` of the variable in an `R`-algebra `A`, `aeval R A x` is the unique `R`-algebra homomorphism from `R[X]` to `A` sending `X` to `x`. -/ def aeval {R : Type u} {A : Type z} [comm_semiring R] [semiring A] [algebra R A] (x : A) : alg_hom R (polynomial R) A := alg_hom.mk (ring_hom.to_fun (eval₂_ring_hom' (algebra_map R A) x sorry)) sorry sorry sorry sorry sorry theorem alg_hom_ext {R : Type u} {A : Type z} [comm_semiring R] [semiring A] [algebra R A] {f : alg_hom R (polynomial R) A} {g : alg_hom R (polynomial R) A} (h : coe_fn f X = coe_fn g X) : f = g := add_monoid_algebra.alg_hom_ext' (monoid_hom.ext_mnat h) theorem aeval_def {R : Type u} {A : Type z} [comm_semiring R] [semiring A] [algebra R A] (x : A) (p : polynomial R) : coe_fn (aeval x) p = eval₂ (algebra_map R A) x p := rfl @[simp] theorem aeval_zero {R : Type u} {A : Type z} [comm_semiring R] [semiring A] [algebra R A] (x : A) : coe_fn (aeval x) 0 = 0 := alg_hom.map_zero (aeval x) @[simp] theorem aeval_X {R : Type u} {A : Type z} [comm_semiring R] [semiring A] [algebra R A] (x : A) : coe_fn (aeval x) X = x := eval₂_X (algebra_map R A) x @[simp] theorem aeval_C {R : Type u} {A : Type z} [comm_semiring R] [semiring A] [algebra R A] (x : A) (r : R) : coe_fn (aeval x) (coe_fn C r) = coe_fn (algebra_map R A) r := eval₂_C (algebra_map R A) x theorem aeval_monomial {R : Type u} {A : Type z} [comm_semiring R] [semiring A] [algebra R A] (x : A) {n : ℕ} {r : R} : coe_fn (aeval x) (coe_fn (monomial n) r) = coe_fn (algebra_map R A) r * x ^ n := eval₂_monomial (algebra_map R A) x @[simp] theorem aeval_X_pow {R : Type u} {A : Type z} [comm_semiring R] [semiring A] [algebra R A] (x : A) {n : ℕ} : coe_fn (aeval x) (X ^ n) = x ^ n := eval₂_X_pow (algebra_map R A) x @[simp] theorem aeval_add {R : Type u} {A : Type z} [comm_semiring R] {p : polynomial R} {q : polynomial R} [semiring A] [algebra R A] (x : A) : coe_fn (aeval x) (p + q) = coe_fn (aeval x) p + coe_fn (aeval x) q := alg_hom.map_add (aeval x) p q @[simp] theorem aeval_one {R : Type u} {A : Type z} [comm_semiring R] [semiring A] [algebra R A] (x : A) : coe_fn (aeval x) 1 = 1 := alg_hom.map_one (aeval x) @[simp] theorem aeval_bit0 {R : Type u} {A : Type z} [comm_semiring R] {p : polynomial R} [semiring A] [algebra R A] (x : A) : coe_fn (aeval x) (bit0 p) = bit0 (coe_fn (aeval x) p) := alg_hom.map_bit0 (aeval x) p @[simp] theorem aeval_bit1 {R : Type u} {A : Type z} [comm_semiring R] {p : polynomial R} [semiring A] [algebra R A] (x : A) : coe_fn (aeval x) (bit1 p) = bit1 (coe_fn (aeval x) p) := alg_hom.map_bit1 (aeval x) p @[simp] theorem aeval_nat_cast {R : Type u} {A : Type z} [comm_semiring R] [semiring A] [algebra R A] (x : A) (n : ℕ) : coe_fn (aeval x) ↑n = ↑n := alg_hom.map_nat_cast (aeval x) n theorem aeval_mul {R : Type u} {A : Type z} [comm_semiring R] {p : polynomial R} {q : polynomial R} [semiring A] [algebra R A] (x : A) : coe_fn (aeval x) (p * q) = coe_fn (aeval x) p * coe_fn (aeval x) q := alg_hom.map_mul (aeval x) p q theorem aeval_comp {R : Type u} [comm_semiring R] {p : polynomial R} {q : polynomial R} {A : Type u_1} [comm_semiring A] [algebra R A] (x : A) : coe_fn (aeval x) (comp p q) = coe_fn (aeval (coe_fn (aeval x) q)) p := eval₂_comp (algebra_map R A) @[simp] theorem aeval_map {R : Type u} [comm_semiring R] {B : Type u_1} [semiring B] [algebra R B] {A : Type u_2} [comm_semiring A] [algebra R A] [algebra A B] [is_scalar_tower R A B] (b : B) (p : polynomial R) : coe_fn (aeval b) (map (algebra_map R A) p) = coe_fn (aeval b) p := sorry theorem eval_unique {R : Type u} {A : Type z} [comm_semiring R] [semiring A] [algebra R A] (φ : alg_hom R (polynomial R) A) (p : polynomial R) : coe_fn φ p = eval₂ (algebra_map R A) (coe_fn φ X) p := sorry theorem aeval_alg_hom {R : Type u} {A : Type z} [comm_semiring R] [semiring A] [algebra R A] {B : Type u_1} [semiring B] [algebra R B] (f : alg_hom R A B) (x : A) : aeval (coe_fn f x) = alg_hom.comp f (aeval x) := sorry theorem aeval_alg_hom_apply {R : Type u} {A : Type z} [comm_semiring R] [semiring A] [algebra R A] {B : Type u_1} [semiring B] [algebra R B] (f : alg_hom R A B) (x : A) (p : polynomial R) : coe_fn (aeval (coe_fn f x)) p = coe_fn f (coe_fn (aeval x) p) := iff.mp alg_hom.ext_iff (aeval_alg_hom f x) p @[simp] theorem coe_aeval_eq_eval {R : Type u} [comm_semiring R] (r : R) : ⇑(aeval r) = eval r := rfl theorem coeff_zero_eq_aeval_zero {R : Type u} [comm_semiring R] (p : polynomial R) : coeff p 0 = coe_fn (aeval 0) p := sorry theorem pow_comp {R : Type u} [comm_semiring R] (p : polynomial R) (q : polynomial R) (k : ℕ) : comp (p ^ k) q = comp p q ^ k := sorry theorem is_root_of_eval₂_map_eq_zero {R : Type u} {S : Type v} [comm_semiring R] {p : polynomial R} [comm_ring S] {f : R →+* S} (hf : function.injective ⇑f) {r : R} : eval₂ f (coe_fn f r) p = 0 → is_root p r := sorry theorem is_root_of_aeval_algebra_map_eq_zero {R : Type u} {S : Type v} [comm_semiring R] [comm_ring S] [algebra R S] {p : polynomial R} (inj : function.injective ⇑(algebra_map R S)) {r : R} (hr : coe_fn (aeval (coe_fn (algebra_map R S) r)) p = 0) : is_root p r := is_root_of_eval₂_map_eq_zero inj hr theorem dvd_term_of_dvd_eval_of_dvd_terms {S : Type v} [comm_ring S] {z : S} {p : S} {f : polynomial S} (i : ℕ) (dvd_eval : p ∣ eval z f) (dvd_terms : ∀ (j : ℕ), j ≠ i → p ∣ coeff f j * z ^ j) : p ∣ coeff f i * z ^ i := sorry theorem dvd_term_of_is_root_of_dvd_terms {S : Type v} [comm_ring S] {r : S} {p : S} {f : polynomial S} (i : ℕ) (hr : is_root f r) (h : ∀ (j : ℕ), j ≠ i → p ∣ coeff f j * r ^ j) : p ∣ coeff f i * r ^ i := dvd_term_of_dvd_eval_of_dvd_terms i (Eq.symm hr ▸ dvd_zero p) h theorem aeval_eq_sum_range {R : Type u} {S : Type v} [comm_semiring R] [comm_ring S] [algebra R S] {p : polynomial R} (x : S) : coe_fn (aeval x) p = finset.sum (finset.range (nat_degree p + 1)) fun (i : ℕ) => coeff p i • x ^ i := sorry theorem aeval_eq_sum_range' {R : Type u} {S : Type v} [comm_semiring R] [comm_ring S] [algebra R S] {p : polynomial R} {n : ℕ} (hn : nat_degree p < n) (x : S) : coe_fn (aeval x) p = finset.sum (finset.range n) fun (i : ℕ) => coeff p i • x ^ i := sorry /-- The evaluation map is not generally multiplicative when the coefficient ring is noncommutative, but nevertheless any polynomial of the form `p * (X - monomial 0 r)` is sent to zero when evaluated at `r`. This is the key step in our proof of the Cayley-Hamilton theorem. -/ theorem eval_mul_X_sub_C {R : Type u} [ring R] {p : polynomial R} (r : R) : eval r (p * (X - coe_fn C r)) = 0 := sorry theorem not_is_unit_X_sub_C {R : Type u} [ring R] [nontrivial R] {r : R} : ¬is_unit (X - coe_fn C r) := sorry theorem aeval_endomorphism {R : Type u} {M : Type u_1} [comm_ring R] [add_comm_group M] [module R M] (f : linear_map R M M) (v : M) (p : polynomial R) : coe_fn (coe_fn (aeval f) p) v = finsupp.sum p fun (n : ℕ) (b : R) => b • coe_fn (f ^ n) v := sorry
de5ff0ca7df245ba023c0129965f426dc5eb6e7b
439bc6c3e74a118aa51df633b8e1f24415804d86
/coverage.lean
fb6de1f39401b40bc08581010a3217cc02faabc9
[]
no_license
jcommelin/lt2019_slides
4ca498db02b5187c5778c21b985126d52d260696
3234cd92920d3d4321cc2cef78b48e5fa55be413
refs/heads/master
1,586,718,101,957
1,546,930,855,000
1,546,930,855,000
162,697,592
1
0
null
null
null
null
UTF-8
Lean
false
false
269
lean
structure coverage := (covers : Π (U : X), set (covering_family U)) (property : ∀ {U V : X} (g : V ⟶ U), ∀ f ∈ covers U, ∃ h ∈ covers V, ∀ Vj ∈ (h : set _), ∃ (Ui ∈ f), nonempty $ ((over.map g).obj Vj) ⟶ Ui)
4ab6b377158903725043f44bc16d34d5cd1f7f6b
cb1829c15cd3d28210f93507f96dfb1f56ec0128
/theorem_proving/04-exercises.lean
2f8c26e09cd972eb2f9ca95488f441f41350862a
[]
no_license
williamdemeo/LEAN_wjd
69f9f76e35092b89e4479a320be2fa3c18aed6fe
13826c75c06ef435166a26a72e76fe984c15bad7
refs/heads/master
1,609,516,630,137
1,518,123,893,000
1,518,123,893,000
97,740,278
2
0
null
null
null
null
UTF-8
Lean
false
false
1,066
lean
namespace Sec_4_6 namespace exercise1 variables (α : Type) (p q : α → Prop) example : (∀ x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) := iff.intro (assume h : ∀ x, p x ∧ q x, and.intro (assume w, show p w, from (h w).left) (assume w, show q w, from (h w).right)) (assume h : (∀ x, p x) ∧ (∀ x, q x), assume w, ⟨(h.left w), (h.right w)⟩) example : (∀ x, (p x → q x)) → (∀ x, p x) → (∀ x, q x) := assume h₁ : ∀ x, (p x → q x), assume h₂ : (∀ x, p x), assume w, have h₃ : p w, from h₂ w, show q w, from h₁ w h₃ example : (∀ x, p x) ∨ (∀ x, q x) → (∀ x, p x ∨ q x) := assume h: (∀ x, p x) ∨ (∀ x, q x), assume w, or.elim h (assume hl : ∀ x, p x, show p w ∨ q w, from or.intro_left _ (hl w)) (assume hr : ∀ x, q x, show p w ∨ q w, from or.intro_right _ (hr w)) end exercise1 end Sec_4_6
b08cff1c2401391f351bfdef5b05e4005c481a6b
680b0d1592ce164979dab866b232f6fa743f2cc8
/library/theories/analysis/real_limit.lean
d4c605a87fbd43bcbecc2876aaeb823ae40c17bb
[ "Apache-2.0" ]
permissive
syohex/lean
657428ab520f8277fc18cf04bea2ad200dbae782
081ad1212b686780f3ff8a6d0e5f8a1d29a7d8bc
refs/heads/master
1,611,274,838,635
1,452,668,188,000
1,452,668,188,000
49,562,028
0
0
null
1,452,675,604,000
1,452,675,602,000
null
UTF-8
Lean
false
false
34,444
lean
/- Copyright (c) 2015 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Robert Y. Lewis Instantiates the reals as a metric space, and expresses completeness, sup, and inf in a manner that is less constructive, but more convenient, than the way it is done in data.real.complete. The definitions here are noncomputable, for various reasons: (1) We rely on the nonconstructive definition of abs. (2) The theory of the reals uses the "some" operator e.g. to define the ceiling function. This can't be defined constructively as an operation on the quotient, because such a function is not continuous. (3) We use "forall" and "exists" to say that a series converges, rather than carrying around rates of convergence explicitly. We then use "some" whenever we need to extract information, such as the limit. These could be avoided in a constructive theory of analysis, but here we will not follow that route. -/ import .metric_space data.real.complete data.set open real classical noncomputable theory namespace real local postfix ⁻¹ := pnat.inv /- the reals form a metric space -/ protected definition metric_space [instance] : metric_space ℝ := ⦃ metric_space, dist := λ x y, abs (x - y), dist_self := λ x, abstract by rewrite [sub_self, abs_zero] end, eq_of_dist_eq_zero := λ x y, eq_of_abs_sub_eq_zero, dist_comm := abs_sub, dist_triangle := abs_sub_le ⦄ open nat open [class] rat definition converges_to_seq (X : ℕ → ℝ) (y : ℝ) : Prop := ∀ ⦃ε : ℝ⦄, ε > 0 → ∃ N : ℕ, ∀ {n}, n ≥ N → abs (X n - y) < ε proposition converges_to_seq.intro {X : ℕ → ℝ} {y : ℝ} (H : ∀ ⦃ε : ℝ⦄, ε > 0 → ∃ N : ℕ, ∀ {n}, n ≥ N → abs (X n - y) ≤ ε) : converges_to_seq X y := metric_space.converges_to_seq.intro H notation X `⟶` y `in` `ℕ` := converges_to_seq X y definition converges_seq [class] (X : ℕ → ℝ) : Prop := ∃ y, X ⟶ y in ℕ definition limit_seq (X : ℕ → ℝ) [H : converges_seq X] : ℝ := some H proposition converges_to_limit_seq (X : ℕ → ℝ) [H : converges_seq X] : (X ⟶ limit_seq X in ℕ) := some_spec H proposition converges_to_seq_unique {X : ℕ → ℝ} {y₁ y₂ : ℝ} (H₁ : X ⟶ y₁ in ℕ) (H₂ : X ⟶ y₂ in ℕ) : y₁ = y₂ := metric_space.converges_to_seq_unique H₁ H₂ proposition eq_limit_of_converges_to_seq {X : ℕ → ℝ} (y : ℝ) (H : X ⟶ y in ℕ) : y = @limit_seq X (exists.intro y H) := converges_to_seq_unique H (@converges_to_limit_seq X (exists.intro y H)) proposition converges_to_seq_constant (y : ℝ) : (λn, y) ⟶ y in ℕ := metric_space.converges_to_seq_constant y proposition converges_to_seq_offset {X : ℕ → ℝ} {y : ℝ} (k : ℕ) (H : X ⟶ y in ℕ) : (λ n, X (n + k)) ⟶ y in ℕ := metric_space.converges_to_seq_offset k H proposition converges_to_seq_offset_left {X : ℕ → ℝ} {y : ℝ} (k : ℕ) (H : X ⟶ y in ℕ) : (λ n, X (k + n)) ⟶ y in ℕ := metric_space.converges_to_seq_offset_left k H proposition converges_to_set_offset_succ {X : ℕ → ℝ} {y : ℝ} (H : X ⟶ y in ℕ) : (λ n, X (succ n)) ⟶ y in ℕ := metric_space.converges_to_seq_offset_succ H proposition converges_to_seq_of_converges_to_seq_offset {X : ℕ → ℝ} {y : ℝ} {k : ℕ} (H : (λ n, X (n + k)) ⟶ y in ℕ) : X ⟶ y in ℕ := metric_space.converges_to_seq_of_converges_to_seq_offset H proposition converges_to_seq_of_converges_to_seq_offset_left {X : ℕ → ℝ} {y : ℝ} {k : ℕ} (H : (λ n, X (k + n)) ⟶ y in ℕ) : X ⟶ y in ℕ := metric_space.converges_to_seq_of_converges_to_seq_offset_left H proposition converges_to_seq_of_converges_to_seq_offset_succ {X : ℕ → ℝ} {y : ℝ} (H : (λ n, X (succ n)) ⟶ y in ℕ) : X ⟶ y in ℕ := metric_space.converges_to_seq_of_converges_to_seq_offset_succ H proposition converges_to_seq_offset_iff (X : ℕ → ℝ) (y : ℝ) (k : ℕ) : ((λ n, X (n + k)) ⟶ y in ℕ) ↔ (X ⟶ y in ℕ) := metric_space.converges_to_seq_offset_iff X y k proposition converges_to_seq_offset_left_iff (X : ℕ → ℝ) (y : ℝ) (k : ℕ) : ((λ n, X (k + n)) ⟶ y in ℕ) ↔ (X ⟶ y in ℕ) := metric_space.converges_to_seq_offset_left_iff X y k proposition converges_to_seq_offset_succ_iff (X : ℕ → ℝ) (y : ℝ) : ((λ n, X (succ n)) ⟶ y in ℕ) ↔ (X ⟶ y in ℕ) := metric_space.converges_to_seq_offset_succ_iff X y /- the completeness of the reals, "translated" from data.real.complete -/ definition cauchy (X : ℕ → ℝ) := metric_space.cauchy X section open pnat subtype private definition pnat.succ (n : ℕ) : ℕ+ := tag (succ n) !succ_pos private definition r_seq_of (X : ℕ → ℝ) : r_seq := λ n, X (elt_of n) private lemma rate_of_cauchy_aux {X : ℕ → ℝ} (H : cauchy X) : ∀ k : ℕ+, ∃ N : ℕ+, ∀ m n : ℕ+, m ≥ N → n ≥ N → abs (X (elt_of m) - X (elt_of n)) ≤ of_rat k⁻¹ := take k : ℕ+, have H1 : (k⁻¹ > (rat.of_num 0)), from !pnat.inv_pos, have H2 : (of_rat k⁻¹ > of_rat (rat.of_num 0)), from !of_rat_lt_of_rat_of_lt H1, obtain (N : ℕ) (H : ∀ m n, m ≥ N → n ≥ N → abs (X m - X n) < of_rat k⁻¹), from H _ H2, exists.intro (pnat.succ N) (take m n : ℕ+, assume Hm : m ≥ (pnat.succ N), assume Hn : n ≥ (pnat.succ N), have Hm' : elt_of m ≥ N, begin apply le.trans, apply le_succ, apply Hm end, have Hn' : elt_of n ≥ N, begin apply le.trans, apply le_succ, apply Hn end, show abs (X (elt_of m) - X (elt_of n)) ≤ of_rat k⁻¹, from le_of_lt (H _ _ Hm' Hn')) private definition rate_of_cauchy {X : ℕ → ℝ} (H : cauchy X) (k : ℕ+) : ℕ+ := some (rate_of_cauchy_aux H k) private lemma cauchy_with_rate_of_cauchy {X : ℕ → ℝ} (H : cauchy X) : cauchy_with_rate (r_seq_of X) (rate_of_cauchy H) := take k : ℕ+, some_spec (rate_of_cauchy_aux H k) private lemma converges_to_with_rate_of_cauchy {X : ℕ → ℝ} (H : cauchy X) : ∃ l Nb, converges_to_with_rate (r_seq_of X) l Nb := begin apply exists.intro, apply exists.intro, apply converges_to_with_rate_of_cauchy_with_rate, exact cauchy_with_rate_of_cauchy H end theorem converges_seq_of_cauchy {X : ℕ → ℝ} (H : cauchy X) : converges_seq X := obtain l Nb (conv : converges_to_with_rate (r_seq_of X) l Nb), from converges_to_with_rate_of_cauchy H, exists.intro l (take ε : ℝ, suppose ε > 0, obtain (k' : ℕ) (Hn : 1 / succ k' < ε), from archimedean_small `ε > 0`, let k : ℕ+ := tag (succ k') !succ_pos, N : ℕ+ := Nb k in have Hk : real.of_rat k⁻¹ < ε, by rewrite [↑pnat.inv, of_rat_divide]; exact Hn, exists.intro (elt_of N) (take n : ℕ, assume Hn : n ≥ elt_of N, let n' : ℕ+ := tag n (nat.lt_of_lt_of_le (has_property N) Hn) in have abs (X n - l) ≤ real.of_rat k⁻¹, by apply conv k n' Hn, show abs (X n - l) < ε, from lt_of_le_of_lt this Hk)) protected definition complete_metric_space [reducible] [trans_instance] : complete_metric_space ℝ := ⦃complete_metric_space, real.metric_space, complete := @converges_seq_of_cauchy ⦄ open set private definition exists_is_sup {X : set ℝ} (H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → x ≤ b)) : ∃ y, is_sup X y := let x := some (and.left H), b := some (and.right H) in exists_is_sup_of_inh_of_bdd X x (some_spec (and.left H)) b (some_spec (and.right H)) private definition sup_aux {X : set ℝ} (H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → x ≤ b)) := some (exists_is_sup H) private definition sup_aux_spec {X : set ℝ} (H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → x ≤ b)) : is_sup X (sup_aux H) := some_spec (exists_is_sup H) definition sup (X : set ℝ) : ℝ := if H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → x ≤ b) then sup_aux H else 0 proposition le_sup {x : ℝ} {X : set ℝ} (Hx : x ∈ X) {b : ℝ} (Hb : ∀ x, x ∈ X → x ≤ b) : x ≤ sup X := have H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → x ≤ b), from and.intro (exists.intro x Hx) (exists.intro b Hb), by+ rewrite [↑sup, dif_pos H]; exact and.left (sup_aux_spec H) x Hx proposition sup_le {X : set ℝ} (HX : ∃ x, x ∈ X) {b : ℝ} (Hb : ∀ x, x ∈ X → x ≤ b) : sup X ≤ b := have H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → x ≤ b), from and.intro HX (exists.intro b Hb), by+ rewrite [↑sup, dif_pos H]; exact and.right (sup_aux_spec H) b Hb proposition exists_mem_and_lt_of_lt_sup {X : set ℝ} (HX : ∃ x, x ∈ X) {b : ℝ} (Hb : b < sup X) : ∃ x, x ∈ X ∧ b < x := have ¬ ∀ x, x ∈ X → x ≤ b, from assume H, not_le_of_gt Hb (sup_le HX H), obtain x (Hx : ¬ (x ∈ X → x ≤ b)), from exists_not_of_not_forall this, exists.intro x (have x ∈ X ∧ ¬ x ≤ b, by rewrite [-not_implies_iff_and_not]; apply Hx, and.intro (and.left this) (lt_of_not_ge (and.right this))) private definition exists_is_inf {X : set ℝ} (H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → b ≤ x)) : ∃ y, is_inf X y := let x := some (and.left H), b := some (and.right H) in exists_is_inf_of_inh_of_bdd X x (some_spec (and.left H)) b (some_spec (and.right H)) private definition inf_aux {X : set ℝ} (H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → b ≤ x)) := some (exists_is_inf H) private definition inf_aux_spec {X : set ℝ} (H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → b ≤ x)) : is_inf X (inf_aux H) := some_spec (exists_is_inf H) definition inf (X : set ℝ) : ℝ := if H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → b ≤ x) then inf_aux H else 0 proposition inf_le {x : ℝ} {X : set ℝ} (Hx : x ∈ X) {b : ℝ} (Hb : ∀ x, x ∈ X → b ≤ x) : inf X ≤ x := have H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → b ≤ x), from and.intro (exists.intro x Hx) (exists.intro b Hb), by+ rewrite [↑inf, dif_pos H]; exact and.left (inf_aux_spec H) x Hx proposition le_inf {X : set ℝ} (HX : ∃ x, x ∈ X) {b : ℝ} (Hb : ∀ x, x ∈ X → b ≤ x) : b ≤ inf X := have H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → b ≤ x), from and.intro HX (exists.intro b Hb), by+ rewrite [↑inf, dif_pos H]; exact and.right (inf_aux_spec H) b Hb proposition exists_mem_and_lt_of_inf_lt {X : set ℝ} (HX : ∃ x, x ∈ X) {b : ℝ} (Hb : inf X < b) : ∃ x, x ∈ X ∧ x < b := have ¬ ∀ x, x ∈ X → b ≤ x, from assume H, not_le_of_gt Hb (le_inf HX H), obtain x (Hx : ¬ (x ∈ X → b ≤ x)), from exists_not_of_not_forall this, exists.intro x (have x ∈ X ∧ ¬ b ≤ x, by rewrite [-not_implies_iff_and_not]; apply Hx, and.intro (and.left this) (lt_of_not_ge (and.right this))) section local attribute mem [quasireducible] -- TODO: is there a better place to put this? proposition image_neg_eq (X : set ℝ) : (λ x, -x) ' X = {x | -x ∈ X} := set.ext (take x, iff.intro (assume H, obtain y [(Hy₁ : y ∈ X) (Hy₂ : -y = x)], from H, show -x ∈ X, by rewrite [-Hy₂, neg_neg]; exact Hy₁) (assume H : -x ∈ X, exists.intro (-x) (and.intro H !neg_neg))) proposition sup_neg {X : set ℝ} (nonempty_X : ∃ x, x ∈ X) {b : ℝ} (Hb : ∀ x, x ∈ X → b ≤ x) : sup {x | -x ∈ X} = - inf X := let negX := {x | -x ∈ X} in have nonempty_negX : ∃ x, x ∈ negX, from obtain x Hx, from nonempty_X, have -(-x) ∈ X, by rewrite neg_neg; apply Hx, exists.intro (-x) this, have H₁ : ∀ x, x ∈ negX → x ≤ - inf X, from take x, assume H, have inf X ≤ -x, from inf_le H Hb, show x ≤ - inf X, from le_neg_of_le_neg this, have H₂ : ∀ x, x ∈ X → -sup negX ≤ x, from take x, assume H, have -(-x) ∈ X, by rewrite neg_neg; apply H, have -x ≤ sup negX, from le_sup this H₁, show -sup negX ≤ x, from !neg_le_of_neg_le this, eq_of_le_of_ge (show sup negX ≤ - inf X, from sup_le nonempty_negX H₁) (show -inf X ≤ sup negX, from !neg_le_of_neg_le (le_inf nonempty_X H₂)) proposition inf_neg {X : set ℝ} (nonempty_X : ∃ x, x ∈ X) {b : ℝ} (Hb : ∀ x, x ∈ X → x ≤ b) : inf {x | -x ∈ X} = - sup X := let negX := {x | -x ∈ X} in have nonempty_negX : ∃ x, x ∈ negX, from obtain x Hx, from nonempty_X, have -(-x) ∈ X, by rewrite neg_neg; apply Hx, exists.intro (-x) this, have Hb' : ∀ x, x ∈ negX → -b ≤ x, from take x, assume H, !neg_le_of_neg_le (Hb _ H), have HX : X = {x | -x ∈ negX}, from set.ext (take x, by rewrite [↑set_of, ↑mem, +neg_neg]), show inf {x | -x ∈ X} = - sup X, using HX Hb' nonempty_negX, by rewrite [HX at {2}, sup_neg nonempty_negX Hb', neg_neg] end end /- limits under pointwise operations -/ section limit_operations open nat variables {X Y : ℕ → ℝ} variables {x y : ℝ} proposition add_converges_to_seq (HX : X ⟶ x in ℕ) (HY : Y ⟶ y in ℕ) : (λ n, X n + Y n) ⟶ x + y in ℕ := take ε, suppose ε > 0, have e2pos : ε / 2 > 0, from div_pos_of_pos_of_pos `ε > 0` two_pos, obtain N₁ (HN₁ : ∀ {n}, n ≥ N₁ → abs (X n - x) < ε / 2), from HX e2pos, obtain N₂ (HN₂ : ∀ {n}, n ≥ N₂ → abs (Y n - y) < ε / 2), from HY e2pos, let N := max N₁ N₂ in exists.intro N (take n, suppose n ≥ N, have ngtN₁ : n ≥ N₁, from nat.le_trans !le_max_left `n ≥ N`, have ngtN₂ : n ≥ N₂, from nat.le_trans !le_max_right `n ≥ N`, show abs ((X n + Y n) - (x + y)) < ε, from calc abs ((X n + Y n) - (x + y)) = abs ((X n - x) + (Y n - y)) : by rewrite [sub_add_eq_sub_sub, *sub_eq_add_neg, *add.assoc, add.left_comm (-x)] ... ≤ abs (X n - x) + abs (Y n - y) : abs_add_le_abs_add_abs ... < ε / 2 + ε / 2 : add_lt_add (HN₁ ngtN₁) (HN₂ ngtN₂) ... = ε : add_halves) private lemma mul_left_converges_to_seq_of_pos {c : ℝ} (cnz : c ≠ 0) (HX : X ⟶ x in ℕ) : (λ n, c * X n) ⟶ c * x in ℕ := take ε, suppose ε > 0, have abscpos : abs c > 0, from abs_pos_of_ne_zero cnz, have epos : ε / abs c > 0, from div_pos_of_pos_of_pos `ε > 0` abscpos, obtain N (HN : ∀ {n}, n ≥ N → abs (X n - x) < ε / abs c), from HX epos, exists.intro N (take n, suppose n ≥ N, have H : abs (X n - x) < ε / abs c, from HN this, show abs (c * X n - c * x) < ε, from calc abs (c * X n - c * x) = abs c * abs (X n - x) : by rewrite [-mul_sub_left_distrib, abs_mul] ... < abs c * (ε / abs c) : mul_lt_mul_of_pos_left H abscpos ... = ε : mul_div_cancel' (ne_of_gt abscpos)) proposition mul_left_converges_to_seq (c : ℝ) (HX : X ⟶ x in ℕ) : (λ n, c * X n) ⟶ c * x in ℕ := by_cases (assume cz : c = 0, have (λ n, c * X n) = (λ n, 0), from funext (take x, by rewrite [cz, zero_mul]), by+ rewrite [this, cz, zero_mul]; apply converges_to_seq_constant) (suppose c ≠ 0, mul_left_converges_to_seq_of_pos this HX) proposition mul_right_converges_to_seq (c : ℝ) (HX : X ⟶ x in ℕ) : (λ n, X n * c) ⟶ x * c in ℕ := have (λ n, X n * c) = (λ n, c * X n), from funext (take x, !mul.comm), by+ rewrite [this, mul.comm]; apply mul_left_converges_to_seq c HX -- TODO: converges_to_seq_div, converges_to_seq_mul_left_iff, etc. proposition neg_converges_to_seq (HX : X ⟶ x in ℕ) : (λ n, - X n) ⟶ - x in ℕ := take ε, suppose ε > 0, obtain N (HN : ∀ {n}, n ≥ N → abs (X n - x) < ε), from HX this, exists.intro N (take n, suppose n ≥ N, show abs (- X n - (- x)) < ε, by rewrite [-neg_neg_sub_neg, *neg_neg, abs_neg]; exact HN `n ≥ N`) proposition neg_converges_to_seq_iff (X : ℕ → ℝ) : ((λ n, - X n) ⟶ - x in ℕ) ↔ (X ⟶ x in ℕ) := have aux : X = λ n, (- (- X n)), from funext (take n, by rewrite neg_neg), iff.intro (assume H : (λ n, -X n)⟶ -x in ℕ, show X ⟶ x in ℕ, by+ rewrite [aux, -neg_neg x]; exact neg_converges_to_seq H) neg_converges_to_seq proposition abs_converges_to_seq_zero (HX : X ⟶ 0 in ℕ) : (λ n, abs (X n)) ⟶ 0 in ℕ := take ε, suppose ε > 0, obtain N (HN : ∀ n, n ≥ N → abs (X n - 0) < ε), from HX `ε > 0`, exists.intro N (take n, assume Hn : n ≥ N, have abs (X n) < ε, begin rewrite -(sub_zero (X n)), apply HN n Hn end, show abs (abs (X n) - 0) < ε, using this, by rewrite [sub_zero, abs_of_nonneg !abs_nonneg]; apply this) proposition converges_to_seq_zero_of_abs_converges_to_seq_zero (HX : (λ n, abs (X n)) ⟶ 0 in ℕ) : X ⟶ 0 in ℕ := take ε, suppose ε > 0, obtain N (HN : ∀ n, n ≥ N → abs (abs (X n) - 0) < ε), from HX `ε > 0`, exists.intro (N : ℕ) (take n : ℕ, assume Hn : n ≥ N, have HN' : abs (abs (X n) - 0) < ε, from HN n Hn, have abs (X n) < ε, by+ rewrite [sub_zero at HN', abs_of_nonneg !abs_nonneg at HN']; apply HN', show abs (X n - 0) < ε, using this, by rewrite sub_zero; apply this) proposition abs_converges_to_seq_zero_iff (X : ℕ → ℝ) : ((λ n, abs (X n)) ⟶ 0 in ℕ) ↔ (X ⟶ 0 in ℕ) := iff.intro converges_to_seq_zero_of_abs_converges_to_seq_zero abs_converges_to_seq_zero -- TODO: products of two sequences, converges_seq, limit_seq end limit_operations /- monotone sequences -/ section monotone_sequences open nat set variable {X : ℕ → ℝ} definition nondecreasing (X : ℕ → ℝ) : Prop := ∀ ⦃i j⦄, i ≤ j → X i ≤ X j proposition nondecreasing_of_forall_le_succ (H : ∀ i, X i ≤ X (succ i)) : nondecreasing X := take i j, suppose i ≤ j, have ∀ n, X i ≤ X (i + n), from take n, nat.induction_on n (by rewrite nat.add_zero; apply le.refl) (take n, assume ih, le.trans ih (H (i + n))), have X i ≤ X (i + (j - i)), from !this, by+ rewrite [add_sub_of_le `i ≤ j` at this]; exact this proposition converges_to_seq_sup_of_nondecreasing (nondecX : nondecreasing X) {b : ℝ} (Hb : ∀ i, X i ≤ b) : X ⟶ sup (X ' univ) in ℕ := let sX := sup (X ' univ) in have Xle : ∀ i, X i ≤ sX, from take i, have ∀ x, x ∈ X ' univ → x ≤ b, from (take x, assume H, obtain i [H' (Hi : X i = x)], from H, by rewrite -Hi; exact Hb i), show X i ≤ sX, from le_sup (mem_image_of_mem X !mem_univ) this, have exX : ∃ x, x ∈ X ' univ, from exists.intro (X 0) (mem_image_of_mem X !mem_univ), take ε, assume epos : ε > 0, have sX - ε < sX, from !sub_lt_of_pos epos, obtain x' [(H₁x' : x' ∈ X ' univ) (H₂x' : sX - ε < x')], from exists_mem_and_lt_of_lt_sup exX this, obtain i [H' (Hi : X i = x')], from H₁x', have Hi' : ∀ j, j ≥ i → sX - ε < X j, from take j, assume Hj, lt_of_lt_of_le (by rewrite Hi; apply H₂x') (nondecX Hj), exists.intro i (take j, assume Hj : j ≥ i, have X j - sX ≤ 0, from sub_nonpos_of_le (Xle j), have eq₁ : abs (X j - sX) = sX - X j, using this, by rewrite [abs_of_nonpos this, neg_sub], have sX - ε < X j, from lt_of_lt_of_le (by rewrite Hi; apply H₂x') (nondecX Hj), have sX < X j + ε, from lt_add_of_sub_lt_right this, have sX - X j < ε, from sub_lt_left_of_lt_add this, show (abs (X j - sX)) < ε, using eq₁ this, by rewrite eq₁; exact this) definition nonincreasing (X : ℕ → ℝ) : Prop := ∀ ⦃i j⦄, i ≤ j → X i ≥ X j proposition nodecreasing_of_nonincreasing_neg (nonincX : nonincreasing (λ n, - X n)) : nondecreasing (λ n, X n) := take i j, suppose i ≤ j, show X i ≤ X j, from le_of_neg_le_neg (nonincX this) proposition noincreasing_neg_of_nondecreasing (nondecX : nondecreasing X) : nonincreasing (λ n, - X n) := take i j, suppose i ≤ j, show - X i ≥ - X j, from neg_le_neg (nondecX this) proposition nonincreasing_neg_iff (X : ℕ → ℝ) : nonincreasing (λ n, - X n) ↔ nondecreasing X := iff.intro nodecreasing_of_nonincreasing_neg noincreasing_neg_of_nondecreasing proposition nonincreasing_of_nondecreasing_neg (nondecX : nondecreasing (λ n, - X n)) : nonincreasing (λ n, X n) := take i j, suppose i ≤ j, show X i ≥ X j, from le_of_neg_le_neg (nondecX this) proposition nodecreasing_neg_of_nonincreasing (nonincX : nonincreasing X) : nondecreasing (λ n, - X n) := take i j, suppose i ≤ j, show - X i ≤ - X j, from neg_le_neg (nonincX this) proposition nondecreasing_neg_iff (X : ℕ → ℝ) : nondecreasing (λ n, - X n) ↔ nonincreasing X := iff.intro nonincreasing_of_nondecreasing_neg nodecreasing_neg_of_nonincreasing proposition nonincreasing_of_forall_succ_le (H : ∀ i, X (succ i) ≤ X i) : nonincreasing X := begin rewrite -nondecreasing_neg_iff, show nondecreasing (λ n : ℕ, - X n), from nondecreasing_of_forall_le_succ (take i, neg_le_neg (H i)) end proposition converges_to_seq_inf_of_nonincreasing (nonincX : nonincreasing X) {b : ℝ} (Hb : ∀ i, b ≤ X i) : X ⟶ inf (X ' univ) in ℕ := have H₁ : ∃ x, x ∈ X ' univ, from exists.intro (X 0) (mem_image_of_mem X !mem_univ), have H₂ : ∀ x, x ∈ X ' univ → b ≤ x, from (take x, assume H, obtain i [Hi₁ (Hi₂ : X i = x)], from H, show b ≤ x, by rewrite -Hi₂; apply Hb i), have H₃ : {x : ℝ | -x ∈ X ' univ} = {x : ℝ | x ∈ (λ n, -X n) ' univ}, from calc {x : ℝ | -x ∈ X ' univ} = (λ y, -y) ' (X ' univ) : by rewrite image_neg_eq ... = {x : ℝ | x ∈ (λ n, -X n) ' univ} : image_compose, have H₄ : ∀ i, - X i ≤ - b, from take i, neg_le_neg (Hb i), begin+ rewrite [-neg_converges_to_seq_iff, -sup_neg H₁ H₂, H₃, -nondecreasing_neg_iff at nonincX], apply converges_to_seq_sup_of_nondecreasing nonincX H₄ end end monotone_sequences section xn open nat set theorem pow_converges_to_seq_zero {x : ℝ} (H : abs x < 1) : (λ n, x^n) ⟶ 0 in ℕ := suffices H' : (λ n, (abs x)^n) ⟶ 0 in ℕ, from have (λ n, (abs x)^n) = (λ n, abs (x^n)), from funext (take n, eq.symm !abs_pow), using this, by rewrite this at H'; exact converges_to_seq_zero_of_abs_converges_to_seq_zero H', let aX := (λ n, (abs x)^n), iaX := inf (aX ' univ), asX := (λ n, (abs x)^(succ n)) in have noninc_aX : nonincreasing aX, from nonincreasing_of_forall_succ_le (take i, assert (abs x) * (abs x)^i ≤ 1 * (abs x)^i, from mul_le_mul_of_nonneg_right (le_of_lt H) (!pow_nonneg_of_nonneg !abs_nonneg), assert (abs x) * (abs x)^i ≤ (abs x)^i, by krewrite one_mul at this; exact this, show (abs x) ^ (succ i) ≤ (abs x)^i, by rewrite pow_succ; apply this), have bdd_aX : ∀ i, 0 ≤ aX i, from take i, !pow_nonneg_of_nonneg !abs_nonneg, assert aXconv : aX ⟶ iaX in ℕ, from converges_to_seq_inf_of_nonincreasing noninc_aX bdd_aX, have asXconv : asX ⟶ iaX in ℕ, from metric_space.converges_to_seq_offset_succ aXconv, have asXconv' : asX ⟶ (abs x) * iaX in ℕ, from mul_left_converges_to_seq (abs x) aXconv, have iaX = (abs x) * iaX, from converges_to_seq_unique asXconv asXconv', assert iaX = 0, from eq_zero_of_mul_eq_self_left (ne_of_lt H) (eq.symm this), show aX ⟶ 0 in ℕ, begin rewrite -this, exact aXconv end --from this ▸ aXconv end xn section continuous -- this definition should be inherited from metric_space once a migrate is done. definition continuous (f : ℝ → ℝ) := ∀ x : ℝ, ∀ ⦃ε : ℝ⦄, ε > 0 → ∃ δ : ℝ, δ > 0 ∧ ∀ x' : ℝ, abs (x - x') < δ → abs (f x - f x') < ε theorem pos_on_nbhd_of_cts_of_pos {f : ℝ → ℝ} (Hf : continuous f) {b : ℝ} (Hb : f b > 0) : ∃ δ : ℝ, δ > 0 ∧ ∀ y, abs (b - y) < δ → f y > 0 := begin let Hcont := Hf b Hb, cases Hcont with δ Hδ, existsi δ, split, exact and.left Hδ, intro y Hy, let Hy' := and.right Hδ y Hy, note Hlt := sub_lt_of_abs_sub_lt_right Hy', rewrite sub_self at Hlt, assumption end theorem neg_on_nbhd_of_cts_of_neg {f : ℝ → ℝ} (Hf : continuous f) {b : ℝ} (Hb : f b < 0) : ∃ δ : ℝ, δ > 0 ∧ ∀ y, abs (b - y) < δ → f y < 0 := begin let Hcont := Hf b (neg_pos_of_neg Hb), cases Hcont with δ Hδ, existsi δ, split, exact and.left Hδ, intro y Hy, let Hy' := and.right Hδ y Hy, let Hlt := sub_lt_of_abs_sub_lt_left Hy', note Hlt' := lt_add_of_sub_lt_right Hlt, rewrite [-sub_eq_add_neg at Hlt', sub_self at Hlt'], assumption end theorem neg_continuous_of_continuous {f : ℝ → ℝ} (Hcon : continuous f) : continuous (λ x, - f x) := begin intros x ε Hε, cases Hcon x Hε with δ Hδ, cases Hδ with Hδ₁ Hδ₂, existsi δ, split, assumption, intros x' Hx', let HD := Hδ₂ x' Hx', rewrite [-abs_neg, neg_neg_sub_neg], exact HD end theorem translate_continuous_of_continuous {f : ℝ → ℝ} (Hcon : continuous f) (a : ℝ) : continuous (λ x, (f x) + a) := begin intros x ε Hε, cases Hcon x Hε with δ Hδ, cases Hδ with Hδ₁ Hδ₂, existsi δ, split, assumption, intros x' Hx', rewrite [add_sub_comm, sub_self, add_zero], apply Hδ₂, assumption end end continuous section inter_val open set private definition inter_sup (a b : ℝ) (f : ℝ → ℝ) := sup {x | x < b ∧ f x < 0} section parameters {f : ℝ → ℝ} (Hf : continuous f) {a b : ℝ} (Hab : a < b) (Ha : f a < 0) (Hb : f b > 0) include Hf Ha Hb Hab private theorem Hinh : ∃ x, x ∈ {x | x < b ∧ f x < 0} := exists.intro a (and.intro Hab Ha) private theorem Hmem : ∀ x, x ∈ {x | x < b ∧ f x < 0} → x ≤ b := λ x Hx, le_of_lt (and.left Hx) private theorem Hsupleb : inter_sup a b f ≤ b := sup_le (Hinh) Hmem local notation 2 := of_num 1 + of_num 1 private theorem ex_delta_lt {x : ℝ} (Hx : f x < 0) (Hxb : x < b) : ∃ δ : ℝ, δ > 0 ∧ x + δ < b ∧ f (x + δ) < 0 := begin let Hcont := neg_on_nbhd_of_cts_of_neg Hf Hx, cases Hcont with δ Hδ, {cases em (x + δ < b) with Haδ Haδ, existsi δ / 2, split, {exact div_pos_of_pos_of_pos (and.left Hδ) two_pos}, split, {apply lt.trans, apply add_lt_add_left, exact div_two_lt_of_pos (and.left Hδ), exact Haδ}, {apply and.right Hδ, krewrite [sub_add_eq_sub_sub, sub_self, zero_sub, abs_neg, abs_of_pos (div_pos_of_pos_of_pos (and.left Hδ) two_pos)], exact div_two_lt_of_pos (and.left Hδ)}, existsi (b - x) / 2, split, {apply div_pos_of_pos_of_pos, exact sub_pos_of_lt Hxb, exact two_pos}, split, {apply add_midpoint Hxb}, {apply and.right Hδ, krewrite [sub_add_eq_sub_sub, sub_self, zero_sub, abs_neg, abs_of_pos (div_pos_of_pos_of_pos (sub_pos_of_lt Hxb) two_pos)], apply lt_of_lt_of_le, apply div_two_lt_of_pos (sub_pos_of_lt Hxb), apply sub_left_le_of_le_add, apply le_of_not_gt Haδ}} end private lemma sup_near_b {δ : ℝ} (Hpos : 0 < δ) (Hgeb : inter_sup a b f + δ / 2 ≥ b) : abs (inter_sup a b f - b) < δ := begin apply abs_lt_of_lt_of_neg_lt, apply sub_lt_left_of_lt_add, apply lt_of_le_of_lt, apply Hsupleb, apply lt_add_of_pos_right Hpos, rewrite neg_sub, apply sub_lt_left_of_lt_add, apply lt_of_le_of_lt, apply Hgeb, apply add_lt_add_left, apply div_two_lt_of_pos Hpos end private lemma delta_of_lt (Hflt : f (inter_sup a b f) < 0) : ∃ δ : ℝ, δ > 0 ∧ inter_sup a b f + δ < b ∧ f (inter_sup a b f + δ) < 0 := if Hlt : inter_sup a b f < b then ex_delta_lt Hflt Hlt else begin let Heq := eq_of_le_of_ge Hsupleb (le_of_not_gt Hlt), apply absurd Hflt, apply not_lt_of_ge, apply le_of_lt, rewrite Heq, exact Hb end private theorem sup_fn_interval_aux1 : f (inter_sup a b f) ≥ 0 := have ¬ f (inter_sup a b f) < 0, from (suppose f (inter_sup a b f) < 0, obtain δ Hδ, from delta_of_lt this, have inter_sup a b f + δ ∈ {x | x < b ∧ f x < 0}, from and.intro (and.left (and.right Hδ)) (and.right (and.right Hδ)), have ¬ inter_sup a b f < inter_sup a b f + δ, from not_lt_of_ge (le_sup this Hmem), show false, from this (lt_add_of_pos_right (and.left Hδ))), le_of_not_gt this private theorem sup_fn_interval_aux2 : f (inter_sup a b f) ≤ 0 := have ¬ f (inter_sup a b f) > 0, from (assume Hfsup : f (inter_sup a b f) > 0, obtain δ Hδ, from pos_on_nbhd_of_cts_of_pos Hf Hfsup, have ∀ x, x ∈ {x | x < b ∧ f x < 0} → x ≤ inter_sup a b f - δ / 2, from (take x, assume Hxset : x ∈ {x | x < b ∧ f x < 0}, have ¬ x > inter_sup a b f - δ / 2, from (assume Hngt, have Habs : abs (inter_sup a b f - x) < δ, begin apply abs_lt_of_lt_of_neg_lt, apply sub_lt_of_sub_lt, apply gt.trans, exact Hngt, apply sub_lt_sub_left, exact div_two_lt_of_pos (and.left Hδ), rewrite neg_sub, apply lt_of_le_of_lt, rotate 1, apply and.left Hδ, apply sub_nonpos_of_le, apply le_sup, exact Hxset, exact Hmem end, have f x > 0, from and.right Hδ x Habs, show false, from (not_lt_of_gt this) (and.right Hxset)), le_of_not_gt this), have Hle : inter_sup a b f ≤ inter_sup a b f - δ / 2, from sup_le Hinh this, show false, from not_le_of_gt (sub_lt_of_pos _ (div_pos_of_pos_of_pos (and.left Hδ) (two_pos))) Hle), le_of_not_gt this private theorem sup_fn_interval : f (inter_sup a b f) = 0 := eq_of_le_of_ge sup_fn_interval_aux2 sup_fn_interval_aux1 private theorem intermediate_value_incr_aux2 : ∃ δ : ℝ, δ > 0 ∧ a + δ < b ∧ f (a + δ) < 0 := begin let Hcont := neg_on_nbhd_of_cts_of_neg Hf Ha, cases Hcont with δ Hδ, {cases em (a + δ < b) with Haδ Haδ, existsi δ / 2, split, {exact div_pos_of_pos_of_pos (and.left Hδ) two_pos}, split, {apply lt.trans, apply add_lt_add_left, exact div_two_lt_of_pos (and.left Hδ), exact Haδ}, {apply and.right Hδ, krewrite [sub_add_eq_sub_sub, sub_self, zero_sub, abs_neg, abs_of_pos (div_pos_of_pos_of_pos (and.left Hδ) two_pos)], exact div_two_lt_of_pos (and.left Hδ)}, existsi (b - a) / 2, split, {apply div_pos_of_pos_of_pos, exact sub_pos_of_lt Hab, exact two_pos}, split, {apply add_midpoint Hab}, {apply and.right Hδ, krewrite [sub_add_eq_sub_sub, sub_self, zero_sub, abs_neg, abs_of_pos (div_pos_of_pos_of_pos (sub_pos_of_lt Hab) two_pos)], apply lt_of_lt_of_le, apply div_two_lt_of_pos (sub_pos_of_lt Hab), apply sub_left_le_of_le_add, apply le_of_not_gt Haδ}} end theorem intermediate_value_incr_zero : ∃ c, a < c ∧ c < b ∧ f c = 0 := begin existsi inter_sup a b f, split, {cases intermediate_value_incr_aux2 with δ Hδ, apply lt_of_lt_of_le, apply lt_add_of_pos_right, exact and.left Hδ, apply le_sup, exact and.right Hδ, intro x Hx, apply le_of_lt, exact and.left Hx}, split, {cases pos_on_nbhd_of_cts_of_pos Hf Hb with δ Hδ, apply lt_of_le_of_lt, rotate 1, apply sub_lt_of_pos, exact and.left Hδ, rotate_right 1, apply sup_le, exact exists.intro a (and.intro Hab Ha), intro x Hx, apply le_of_not_gt, intro Hxgt, have Hxgt' : b - x < δ, from sub_lt_of_sub_lt Hxgt, krewrite -(abs_of_pos (sub_pos_of_lt (and.left Hx))) at Hxgt', note Hxgt'' := and.right Hδ _ Hxgt', exact not_lt_of_ge (le_of_lt Hxgt'') (and.right Hx)}, {exact sup_fn_interval} end end theorem intermediate_value_decr_zero {f : ℝ → ℝ} (Hf : continuous f) {a b : ℝ} (Hab : a < b) (Ha : f a > 0) (Hb : f b < 0) : ∃ c, a < c ∧ c < b ∧ f c = 0 := begin have Ha' : - f a < 0, from neg_neg_of_pos Ha, have Hb' : - f b > 0, from neg_pos_of_neg Hb, have Hcon : continuous (λ x, - f x), from neg_continuous_of_continuous Hf, let Hiv := intermediate_value_incr_zero Hcon Hab Ha' Hb', cases Hiv with c Hc, existsi c, split, exact and.left Hc, split, exact and.left (and.right Hc), apply eq_zero_of_neg_eq_zero, apply and.right (and.right Hc) end theorem intermediate_value_incr {f : ℝ → ℝ} (Hf : continuous f) {a b : ℝ} (Hab : a < b) {v : ℝ} (Hav : f a < v) (Hbv : f b > v) : ∃ c, a < c ∧ c < b ∧ f c = v := have Hav' : f a - v < 0, from sub_neg_of_lt Hav, have Hbv' : f b - v > 0, from sub_pos_of_lt Hbv, have Hcon : continuous (λ x, f x - v), from translate_continuous_of_continuous Hf _, have Hiv : ∃ c, a < c ∧ c < b ∧ f c - v = 0, from intermediate_value_incr_zero Hcon Hab Hav' Hbv', obtain c Hc, from Hiv, exists.intro c (and.intro (and.left Hc) (and.intro (and.left (and.right Hc)) (eq_of_sub_eq_zero (and.right (and.right Hc))))) theorem intermediate_value_decr {f : ℝ → ℝ} (Hf : continuous f) {a b : ℝ} (Hab : a < b) {v : ℝ} (Hav : f a > v) (Hbv : f b < v) : ∃ c, a < c ∧ c < b ∧ f c = v := have Hav' : f a - v > 0, from sub_pos_of_lt Hav, have Hbv' : f b - v < 0, from sub_neg_of_lt Hbv, have Hcon : continuous (λ x, f x - v), from translate_continuous_of_continuous Hf _, have Hiv : ∃ c, a < c ∧ c < b ∧ f c - v = 0, from intermediate_value_decr_zero Hcon Hab Hav' Hbv', obtain c Hc, from Hiv, exists.intro c (and.intro (and.left Hc) (and.intro (and.left (and.right Hc)) (eq_of_sub_eq_zero (and.right (and.right Hc))))) end inter_val /- proposition converges_to_at_unique {f : M → N} {y₁ y₂ : N} {x : M} (H₁ : f ⟶ y₁ '[at x]) (H₂ : f ⟶ y₂ '[at x]) : y₁ = y₂ := eq_of_forall_dist_le (take ε, suppose ε > 0, have e2pos : ε / 2 > 0, from div_pos_of_pos_of_pos `ε > 0` two_pos, obtain δ₁ [(δ₁pos : δ₁ > 0) (Hδ₁ : ∀ x', x ≠ x' ∧ dist x x' < δ₁ → dist (f x') y₁ < ε / 2)], from H₁ e2pos, obtain δ₂ [(δ₂pos : δ₂ > 0) (Hδ₂ : ∀ x', x ≠ x' ∧ dist x x' < δ₂ → dist (f x') y₂ < ε / 2)], from H₂ e2pos, let δ := min δ₁ δ₂ in have δ > 0, from lt_min δ₁pos δ₂pos, -/ end real
13de0aae7d28e1cf0c64b33b38f9411a45e9839b
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/src/Init/Data/AC.lean
b59e1a4dec330de07070c249b872318b510c8a18
[ "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
11,671
lean
/- Copyright (c) 2022 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dany Fabian -/ prelude import Init.Classical import Init.Data.List namespace Lean.Data.AC inductive Expr | var (x : Nat) | op (lhs rhs : Expr) deriving Inhabited, Repr, BEq structure Variable {α : Sort u} (op : α → α → α) : Type u where value : α neutral : Option $ IsNeutral op value structure Context (α : Sort u) where op : α → α → α assoc : IsAssociative op comm : Option $ IsCommutative op idem : Option $ IsIdempotent op vars : List (Variable op) arbitrary : α class ContextInformation (α : Sort u) where isNeutral : α → Nat → Bool isComm : α → Bool isIdem : α → Bool class EvalInformation (α : Sort u) (β : Sort v) where arbitrary : α → β evalOp : α → β → β → β evalVar : α → Nat → β def Context.var (ctx : Context α) (idx : Nat) : Variable ctx.op := ctx.vars.getD idx ⟨ctx.arbitrary, none⟩ instance : ContextInformation (Context α) where isNeutral ctx x := ctx.var x |>.neutral.isSome isComm ctx := ctx.comm.isSome isIdem ctx := ctx.idem.isSome instance : EvalInformation (Context α) α where arbitrary ctx := ctx.arbitrary evalOp ctx := ctx.op evalVar ctx idx := ctx.var idx |>.value def eval (β : Sort u) [EvalInformation α β] (ctx : α) : (ex : Expr) → β | Expr.var idx => EvalInformation.evalVar ctx idx | Expr.op l r => EvalInformation.evalOp ctx (eval β ctx l) (eval β ctx r) def Expr.toList : Expr → List Nat | Expr.var idx => [idx] | Expr.op l r => l.toList.append r.toList def evalList (β : Sort u) [EvalInformation α β] (ctx : α) : List Nat → β | [] => EvalInformation.arbitrary ctx | [x] => EvalInformation.evalVar ctx x | x :: xs => EvalInformation.evalOp ctx (EvalInformation.evalVar ctx x) (evalList β ctx xs) def insert (x : Nat) : List Nat → List Nat | [] => [x] | a :: as => if x < a then x :: a :: as else a :: insert x as def sort (xs : List Nat) : List Nat := let rec loop : List Nat → List Nat → List Nat | acc, [] => acc | acc, x :: xs => loop (insert x acc) xs loop [] xs def mergeIdem (xs : List Nat) : List Nat := let rec loop : Nat → List Nat → List Nat | curr, next :: rest => if curr = next then loop curr rest else curr :: loop next rest | curr, [] => [curr] match xs with | [] => [] | x :: xs => loop x xs def removeNeutrals [info : ContextInformation α] (ctx : α) : List Nat → List Nat | x :: xs => match loop (x :: xs) with | [] => [x] | ys => ys | [] => [] where loop : List Nat → List Nat | x :: xs => match info.isNeutral ctx x with | true => loop xs | false => x :: loop xs | [] => [] def norm [info : ContextInformation α] (ctx : α) (e : Expr) : List Nat := let xs := e.toList let xs := removeNeutrals ctx xs let xs := if info.isComm ctx then sort xs else xs if info.isIdem ctx then mergeIdem xs else xs theorem List.two_step_induction {motive : List Nat → Sort u} (l : List Nat) (empty : motive []) (single : ∀ a, motive [a]) (step : ∀ a b l, motive (b :: l) → motive (a :: b :: l)) : motive l := by induction l with | nil => assumption | cons a l => cases l; apply single; apply step; assumption theorem Context.mergeIdem_nonEmpty (e : List Nat) (h : e ≠ []) : mergeIdem e ≠ [] := by induction e using List.two_step_induction with | empty => simp_all | single => simp [mergeIdem, mergeIdem.loop] | step => simp [mergeIdem, mergeIdem.loop] at *; split <;> simp_all theorem Context.mergeIdem_head : mergeIdem (x :: x :: xs) = mergeIdem (x :: xs) := by simp [mergeIdem, mergeIdem.loop] theorem Context.mergeIdem_head2 (h : x ≠ y) : mergeIdem (x :: y :: ys) = x :: mergeIdem (y :: ys) := by simp [mergeIdem, mergeIdem.loop, h] theorem Context.evalList_mergeIdem (ctx : Context α) (h : ContextInformation.isIdem ctx) (e : List Nat) : evalList α ctx (mergeIdem e) = evalList α ctx e := by have h : IsIdempotent ctx.op := by simp [ContextInformation.isIdem, Option.isSome] at h; cases h₂ : ctx.idem <;> simp [h₂] at h; assumption induction e using List.two_step_induction with | empty => rfl | single => rfl | step x y ys ih => cases ys with | nil => simp [mergeIdem, mergeIdem.loop] split case inl h₂ => simp [evalList, h₂, h.1, EvalInformation.evalOp] rfl | cons z zs => by_cases h₂ : x = y case inl => rw [h₂, mergeIdem_head, ih] simp [evalList, ←ctx.assoc.1, h.1, EvalInformation.evalOp] case inr => rw [mergeIdem_head2] by_cases h₃ : y = z case inl => simp [mergeIdem_head, h₃, evalList] cases h₄ : mergeIdem (z :: zs) with | nil => apply absurd h₄; apply mergeIdem_nonEmpty; simp | cons u us => simp_all [mergeIdem, mergeIdem.loop, evalList] case inr => simp [mergeIdem_head2, h₃, evalList] at * rw [ih] assumption theorem insert_nonEmpty : insert x xs ≠ [] := by induction xs with | nil => simp [insert] | cons x xs _ => simp [insert]; split <;> simp theorem Context.sort_loop_nonEmpty (xs : List Nat) (h : xs ≠ []) : sort.loop xs ys ≠ [] := by induction ys generalizing xs with | nil => simp [sort.loop]; assumption | cons y _ ih => simp [sort.loop]; apply ih; apply insert_nonEmpty theorem Context.evalList_insert (ctx : Context α) (h : IsCommutative ctx.op) (x : Nat) (xs : List Nat) : evalList α ctx (insert x xs) = evalList α ctx (x::xs) := by induction xs using List.two_step_induction with | empty => rfl | single => simp [insert] split . rfl . simp [evalList, h.1, EvalInformation.evalOp] | step y z zs ih => simp [insert] at *; split case inl => rfl case inr => split case inl => simp [evalList, EvalInformation.evalOp]; rw [h.1, ctx.assoc.1, h.1 (evalList _ _ _)] case inr => simp_all [evalList, EvalInformation.evalOp]; rw [h.1, ctx.assoc.1, h.1 (evalList _ _ _)] theorem Context.evalList_sort_congr (ctx : Context α) (h : IsCommutative ctx.op) (h₂ : evalList α ctx a = evalList α ctx b) (h₃ : a ≠ []) (h₄ : b ≠ []) : evalList α ctx (sort.loop a c) = evalList α ctx (sort.loop b c) := by induction c generalizing a b with | nil => simp [sort.loop, h₂] | cons c _ ih => simp [sort.loop]; apply ih; simp [evalList_insert ctx h, evalList] cases a with | nil => apply absurd h₃; simp | cons a as => cases b with | nil => apply absurd h₄; simp | cons b bs => simp [evalList, h₂] all_goals apply insert_nonEmpty theorem Context.evalList_sort_loop_swap (ctx : Context α) (h : IsCommutative ctx.op) (xs ys : List Nat) : evalList α ctx (sort.loop xs (y::ys)) = evalList α ctx (sort.loop (y::xs) ys) := by induction ys generalizing y xs with | nil => simp [sort.loop, evalList_insert ctx h] | cons z zs _ => simp [sort.loop]; apply evalList_sort_congr ctx h simp [evalList_insert ctx h] cases h₂ : insert y xs . apply absurd h₂; simp [insert_nonEmpty] . simp [evalList, ←h₂, evalList_insert ctx h] all_goals simp [insert_nonEmpty] theorem Context.evalList_sort_cons (ctx : Context α) (h : IsCommutative ctx.op) (x : Nat) (xs : List Nat) : evalList α ctx (sort (x :: xs)) = evalList α ctx (x :: sort xs) := by simp [sort, sort.loop] generalize [] = ys induction xs generalizing x ys with | nil => simp [sort.loop, evalList_insert ctx h] | cons z zs ih => rw [evalList_sort_loop_swap ctx h]; simp [sort.loop, ←ih]; apply evalList_sort_congr ctx h; rw [evalList_insert ctx h] cases h₂ : insert x ys with | nil => apply absurd h₂; simp [insert_nonEmpty] | cons u us => cases h₃ : insert z ys with | nil => apply absurd h₃; simp [insert_nonEmpty] | cons v vs => simp [evalList, ←h₂, ←h₃, evalList_insert ctx h] cases ys . simp [evalList, h.1, EvalInformation.evalOp] . simp [evalList, EvalInformation.evalOp]; rw [h.1, ctx.assoc.1, h.1 (evalList _ _ _)] all_goals simp [insert_nonEmpty] theorem Context.evalList_sort (ctx : Context α) (h : ContextInformation.isComm ctx) (e : List Nat) : evalList α ctx (sort e) = evalList α ctx e := by have h : IsCommutative ctx.op := by simp [ContextInformation.isComm, Option.isSome] at h; cases h₂ : ctx.comm <;> simp [h₂] at h; assumption induction e using List.two_step_induction with | empty => rfl | single => rfl | step x y ys ih => simp [evalList_sort_cons ctx h] cases h₂ : sort (y :: ys) with | nil => simp [sort, sort.loop] at *; apply absurd h₂; apply sort_loop_nonEmpty; apply insert_nonEmpty | cons z zs => simp [evalList, ←h₂, ih] theorem Context.toList_nonEmpty (e : Expr) : e.toList ≠ [] := by induction e with | var => simp [Expr.toList] | op l r ih₁ _ => simp [Expr.toList] cases h : l.toList with | nil => contradiction | cons => simp [List.append] theorem Context.unwrap_isNeutral {ctx : Context α} {x : Nat} : ContextInformation.isNeutral ctx x = true → IsNeutral (EvalInformation.evalOp ctx) (EvalInformation.evalVar (β := α) ctx x) := by simp [ContextInformation.isNeutral, Option.isSome, EvalInformation.evalOp, EvalInformation.evalVar] match (var ctx x).neutral with | some hn => intro; assumption | none => intro; contradiction theorem Context.evalList_removeNeutrals (ctx : Context α) (e : List Nat) : evalList α ctx (removeNeutrals ctx e) = evalList α ctx e := by induction e using List.two_step_induction with | empty => rfl | single => simp [removeNeutrals, removeNeutrals.loop]; split case h_1 => rfl case h_2 h => split at h <;> simp_all | step x y ys ih => cases h₁ : ContextInformation.isNeutral ctx x <;> cases h₂ : ContextInformation.isNeutral ctx y <;> cases h₃ : removeNeutrals.loop ctx ys <;> simp [removeNeutrals, removeNeutrals.loop, h₁, h₂, h₃, evalList, ←ih] <;> (try simp [unwrap_isNeutral h₂ |>.2]) <;> (try simp [unwrap_isNeutral h₁ |>.1]) theorem Context.evalList_append (ctx : Context α) (l r : List Nat) (h₁ : l ≠ []) (h₂ : r ≠ []) : evalList α ctx (l.append r) = ctx.op (evalList α ctx l) (evalList α ctx r) := by induction l using List.two_step_induction with | empty => simp_all | single x => cases r . simp at h₂ . simp [List.append, evalList, EvalInformation.evalOp] | step x y ys ih => simp [List.append, evalList, EvalInformation.evalOp] at *; rw [ih]; simp [ctx.assoc.1] theorem Context.eval_toList (ctx : Context α) (e : Expr) : evalList α ctx e.toList = eval α ctx e := by induction e with | var x => rfl | op l r ih₁ ih₂ => simp [evalList, Expr.toList, eval, ←ih₁, ←ih₂] apply evalList_append <;> apply toList_nonEmpty theorem Context.eval_norm (ctx : Context α) (e : Expr) : evalList α ctx (norm ctx e) = eval α ctx e := by simp [norm] cases h₁ : ContextInformation.isIdem ctx <;> cases h₂ : ContextInformation.isComm ctx <;> simp_all [evalList_removeNeutrals, eval_toList, toList_nonEmpty, evalList_mergeIdem, evalList_sort] theorem Context.eq_of_norm (ctx : Context α) (a b : Expr) (h : norm ctx a == norm ctx b) : eval α ctx a = eval α ctx b := by have h := congrArg (evalList α ctx) (eq_of_beq h) rw [eval_norm, eval_norm] at h assumption end Lean.Data.AC
8c7164e9c5a38c3c7641c6456fda6fd4e53d9152
aa3f8992ef7806974bc1ffd468baa0c79f4d6643
/library/logic/wf.lean
4ce9fd92f658239ae799d0afc9b335253a9c9a11
[ "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
4,910
lean
-- Copyright (c) 2014 Microsoft Corporation. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Author: Leonardo de Moura import logic.eq logic.relation inductive acc {A : Type} (R : A → A → Prop) : A → Prop := intro : ∀x, (∀ y, R y x → acc R y) → acc R x namespace acc variables {A : Type} {R : A → A → Prop} definition inv {x y : A} (H₁ : acc R x) (H₂ : R y x) : acc R y := acc.rec_on H₁ (λ x₁ ac₁ iH H₂, ac₁ y H₂) H₂ end acc inductive well_founded [class] {A : Type} (R : A → A → Prop) : Prop := intro : (∀ a, acc R a) → well_founded R namespace well_founded definition apply [coercion] {A : Type} {R : A → A → Prop} (wf : well_founded R) : ∀a, acc R a := take a, well_founded.rec_on wf (λp, p) a context parameters {A : Type} {R : A → A → Prop} infix `≺`:50 := R hypothesis [Hwf : well_founded R] theorem recursion {C : A → Type} (a : A) (H : Πx, (Πy, y ≺ x → C y) → C x) : C a := acc.rec_on (Hwf a) (λ x₁ ac₁ iH, H x₁ iH) theorem induction {C : A → Prop} (a : A) (H : ∀x, (∀y, y ≺ x → C y) → C x) : C a := recursion a H variable {C : A → Type} variable F : Πx, (Πy, y ≺ x → C y) → C x definition fix_F (x : A) (a : acc R x) : C x := acc.rec_on a (λ x₁ ac₁ iH, F x₁ iH) theorem fix_F_eq (x : A) (r : acc R x) : fix_F F x r = F x (λ (y : A) (p : y ≺ x), fix_F F y (acc.inv r p)) := have gen : Π r : acc R x, fix_F F x r = F x (λ (y : A) (p : y ≺ x), fix_F F y (acc.inv r p)), from acc.rec_on r (λ x₁ ac iH (r₁ : acc R x₁), -- The proof is straightforward after we replace r₁ with acc.intro (to "unblock" evaluation). calc fix_F F x₁ r₁ = fix_F F x₁ (acc.intro x₁ ac) : proof_irrel r₁ ... = F x₁ (λ y ay, fix_F F y (acc.inv r₁ ay)) : rfl), gen r end variables {A : Type} {C : A → Type} {R : A → A → Prop} -- Well-founded fixpoint definition fix [Hwf : well_founded R] (F : Πx, (Πy, R y x → C y) → C x) (x : A) : C x := fix_F F x (Hwf x) -- Well-founded fixpoint satisfies fixpoint equation theorem fix_eq [Hwf : well_founded R] (F : Πx, (Πy, R y x → C y) → C x) (x : A) : fix F x = F x (λy h, fix F y) := calc -- The proof is straightforward, it just uses fix_F_eq and proof irrelevance fix F x = F x (λy h, fix_F F y (acc.inv (Hwf x) h)) : fix_F_eq F x (Hwf x) ... = F x (λy h, fix F y) : rfl -- proof irrelevance is used here end well_founded open well_founded -- Empty relation is well-founded definition empty.wf {A : Type} : well_founded empty_relation := well_founded.intro (λ (a : A), acc.intro a (λ (b : A) (lt : false), false.rec _ lt)) -- Subrelation of a well-founded relation is well-founded namespace subrelation context parameters {A : Type} {R Q : A → A → Prop} parameters (H₁ : subrelation Q R) parameters (H₂ : well_founded R) definition accessible {a : A} (ac : acc R a) : acc Q a := acc.rec_on ac (λ (x : A) (ax : _) (iH : ∀ (y : A), R y x → acc Q y), acc.intro x (λ (y : A) (lt : Q y x), iH y (H₁ lt))) definition wf : well_founded Q := well_founded.intro (λ a, accessible (H₂ a)) end end subrelation -- The inverse image of a well-founded relation is well-founded namespace inv_image context parameters {A B : Type} {R : B → B → Prop} parameters (f : A → B) parameters (H : well_founded R) definition accessible {a : A} (ac : acc R (f a)) : acc (inv_image R f) a := have gen : ∀x, f x = f a → acc (inv_image R f) x, from acc.rec_on ac (λx acx (iH : ∀y, R y x → (∀z, f z = y → acc (inv_image R f) z)) (z : A) (eq₁ : f z = x), acc.intro z (λ (y : A) (lt : R (f y) (f z)), iH (f y) (eq.rec_on eq₁ lt) y rfl)), gen a rfl definition wf : well_founded (inv_image R f) := well_founded.intro (λ a, accessible (H (f a))) end end inv_image -- The transitive closure of a well-founded relation is well-founded namespace tc context parameters {A : Type} {R : A → A → Prop} notation `R⁺` := tc R definition accessible {z} (ac: acc R z) : acc R⁺ z := acc.rec_on ac (λ x acx (iH : ∀y, R y x → acc R⁺ y), acc.intro x (λ (y : A) (lt : R⁺ y x), have gen : x = x → acc R⁺ y, from tc.rec_on lt (λa b (H : R a b) (Heq : b = x), iH a (eq.rec_on Heq H)) (λa b c (H₁ : R⁺ a b) (H₂ : R⁺ b c) (iH₁ : b = x → acc R⁺ a) (iH₂ : c = x → acc R⁺ b) (Heq : c = x), acc.inv (iH₂ Heq) H₁), gen rfl)) definition wf (H : well_founded R) : well_founded R⁺ := well_founded.intro (λ a, accessible (H a)) end end tc
652c6278c34b74340b7ad5e996b848947cbac2b3
d642a6b1261b2cbe691e53561ac777b924751b63
/src/topology/sequences.lean
288d0e792ffd5db45855d9bffb84ff2782a6b2ce
[ "Apache-2.0" ]
permissive
cipher1024/mathlib
fee56b9954e969721715e45fea8bcb95f9dc03fe
d077887141000fefa5a264e30fa57520e9f03522
refs/heads/master
1,651,806,490,504
1,573,508,694,000
1,573,508,694,000
107,216,176
0
0
Apache-2.0
1,647,363,136,000
1,508,213,014,000
Lean
UTF-8
Lean
false
false
9,931
lean
/- Copyright (c) 2018 Jan-David Salchow. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jan-David Salchow Sequences in topological spaces. In this file we define sequences in topological spaces and show how they are related to filters and the topology. In particular, we * associate a filter with a sequence and prove equivalence of convergence of the two, * define the sequential closure of a set and prove that it's contained in the closure, * define a type class "sequential_space" in which closure and sequential closure agree, * define sequential continuity and show that it coincides with continuity in sequential spaces, * provide an instance that shows that every first-countable (and in particular metric) space is a sequential space. TODO: * Sequential compactness should be handled here. -/ import topology.basic import topology.bases open set filter variables {α : Type*} {β : Type*} local notation f ` ⟶ ` limit := tendsto f at_top (nhds limit) /- Statements about sequences in general topological spaces. -/ section topological_space variables [topological_space α] [topological_space β] /-- A sequence converges in the sence of topological spaces iff the associated statement for filter holds. -/ lemma topological_space.seq_tendsto_iff {x : ℕ → α} {limit : α} : tendsto x at_top (nhds limit) ↔ ∀ U : set α, limit ∈ U → is_open U → ∃ n0 : ℕ, ∀ n ≥ n0, (x n) ∈ U := iff.intro (assume ttol : tendsto x at_top (nhds limit), show ∀ U : set α, limit ∈ U → is_open U → ∃ n0 : ℕ, ∀ n ≥ n0, (x n) ∈ U, from assume U limitInU isOpenU, have {n | (x n) ∈ U} ∈ at_top := mem_map.mp $ le_def.mp ttol U $ mem_nhds_sets isOpenU limitInU, show ∃ n0 : ℕ, ∀ n ≥ n0, (x n) ∈ U, from mem_at_top_sets.mp this) (assume xtol : ∀ U : set α, limit ∈ U → is_open U → ∃ n0 : ℕ, ∀ n ≥ n0, (x n) ∈ U, suffices ∀ U, is_open U → limit ∈ U → x ⁻¹' U ∈ at_top, from tendsto_nhds.mpr this, assume U isOpenU limitInU, suffices ∃ n0 : ℕ, ∀ n ≥ n0, (x n) ∈ U, by simp [this], xtol U limitInU isOpenU) /-- The sequential closure of a subset M ⊆ α of a topological space α is the set of all p ∈ α which arise as limit of sequences in M. -/ def sequential_closure (M : set α) : set α := {p | ∃ x : ℕ → α, (∀ n : ℕ, x n ∈ M) ∧ (x ⟶ p)} lemma subset_sequential_closure (M : set α) : M ⊆ sequential_closure M := assume p (_ : p ∈ M), show p ∈ sequential_closure M, from ⟨λ n, p, assume n, ‹p ∈ M›, tendsto_const_nhds⟩ def is_seq_closed (A : set α) : Prop := A = sequential_closure A /-- A convenience lemma for showing that a set is sequentially closed. -/ lemma is_seq_closed_of_def {A : set α} (h : ∀(x : ℕ → α) (p : α), (∀ n : ℕ, x n ∈ A) → (x ⟶ p) → p ∈ A) : is_seq_closed A := show A = sequential_closure A, from subset.antisymm (subset_sequential_closure A) (show ∀ p, p ∈ sequential_closure A → p ∈ A, from (assume p ⟨x, _, _⟩, show p ∈ A, from h x p ‹∀ n : ℕ, ((x n) ∈ A)› ‹(x ⟶ p)›)) /-- The sequential closure of a set is contained in the closure of that set. The converse is not true. -/ lemma sequential_closure_subset_closure (M : set α) : sequential_closure M ⊆ closure M := show ∀ p, p ∈ sequential_closure M → p ∈ closure M, from assume p, assume : ∃ x : ℕ → α, (∀ n : ℕ, ((x n) ∈ M)) ∧ (x ⟶ p), let ⟨x, ⟨_, _⟩⟩ := this in show p ∈ closure M, from -- we have to show that p is in the closure of M -- using mem_closure_iff, this is equivalent to proving that every open neighbourhood -- has nonempty intersection with M, but this is witnessed by our sequence x suffices ∀ O, is_open O → p ∈ O → O ∩ M ≠ ∅, from mem_closure_iff.mpr this, have ∀ (U : set α), p ∈ U → is_open U → (∃ n0, ∀ n, n ≥ n0 → x n ∈ U), by rwa[←topological_space.seq_tendsto_iff], assume O is_open_O p_in_O, let ⟨n0, _⟩ := this O ‹p ∈ O› ‹is_open O› in have (x n0) ∈ O, from ‹∀ n ≥ n0, x n ∈ O› n0 (show n0 ≥ n0, from le_refl n0), have (x n0) ∈ O ∩ M, from ⟨this, ‹∀n, x n ∈ M› n0⟩, set.ne_empty_of_mem this /-- A set is sequentially closed if it is closed. -/ lemma is_seq_closed_of_is_closed (M : set α) (_ : is_closed M) : is_seq_closed M := suffices sequential_closure M ⊆ M, from set.eq_of_subset_of_subset (subset_sequential_closure M) this, calc sequential_closure M ⊆ closure M : sequential_closure_subset_closure M ... = M : closure_eq_of_is_closed ‹is_closed M› /-- The limit of a convergent sequence in a sequentially closed set is in that set.-/ lemma mem_of_is_seq_closed {A : set α} (_ : is_seq_closed A) {x : ℕ → α} (_ : ∀ n, x n ∈ A) {limit : α} (_ : (x ⟶ limit)) : limit ∈ A := have limit ∈ sequential_closure A, from show ∃ x : ℕ → α, (∀ n : ℕ, x n ∈ A) ∧ (x ⟶ limit), from ⟨x, ‹∀ n, x n ∈ A›, ‹(x ⟶ limit)›⟩, eq.subst (eq.symm ‹is_seq_closed A›) ‹limit ∈ sequential_closure A› /-- The limit of a convergent sequence in a closed set is in that set.-/ lemma mem_of_is_closed_sequential {A : set α} (_ : is_closed A) {x : ℕ → α} (_ : ∀ n, x n ∈ A) {limit : α} (_ : x ⟶ limit) : limit ∈ A := mem_of_is_seq_closed (is_seq_closed_of_is_closed A ‹is_closed A›) ‹∀ n, x n ∈ A› ‹(x ⟶ limit)› /-- A sequential space is a space in which 'sequences are enough to probe the topology'. This can be formalised by demanding that the sequential closure and the closure coincide. The following statements show that other topological properties can be deduced from sequences in sequential spaces. -/ class sequential_space (α : Type*) [topological_space α] : Prop := (sequential_closure_eq_closure : ∀ M : set α, sequential_closure M = closure M) /-- In a sequential space, a set is closed iff it's sequentially closed. -/ lemma is_seq_closed_iff_is_closed [sequential_space α] {M : set α} : is_seq_closed M ↔ is_closed M := iff.intro (assume _, closure_eq_iff_is_closed.mp (eq.symm (calc M = sequential_closure M : by assumption ... = closure M : sequential_space.sequential_closure_eq_closure M))) (is_seq_closed_of_is_closed M) /-- A function between topological spaces is sequentially continuous if it commutes with limit of convergent sequences. -/ def sequentially_continuous (f : α → β) : Prop := ∀ (x : ℕ → α), ∀ {limit : α}, (x ⟶ limit) → (f∘x ⟶ f limit) /- A continuous function is sequentially continuous. -/ lemma continuous.to_sequentially_continuous {f : α → β} (_ : continuous f) : sequentially_continuous f := assume x limit (_ : x ⟶ limit), have tendsto f (nhds limit) (nhds (f limit)), from continuous.tendsto ‹continuous f› limit, show (f ∘ x) ⟶ (f limit), from tendsto.comp this ‹(x ⟶ limit)› /-- In a sequential space, continuity and sequential continuity coincide. -/ lemma continuous_iff_sequentially_continuous {f : α → β} [sequential_space α] : continuous f ↔ sequentially_continuous f := iff.intro (assume _, ‹continuous f›.to_sequentially_continuous) (assume : sequentially_continuous f, show continuous f, from suffices h : ∀ {A : set β}, is_closed A → is_seq_closed (f ⁻¹' A), from continuous_iff_is_closed.mpr (assume A _, is_seq_closed_iff_is_closed.mp $ h ‹is_closed A›), assume A (_ : is_closed A), is_seq_closed_of_def $ assume (x : ℕ → α) p (_ : ∀ n, f (x n) ∈ A) (_ : x ⟶ p), have (f ∘ x) ⟶ (f p), from ‹sequentially_continuous f› x ‹(x ⟶ p)›, show f p ∈ A, from mem_of_is_closed_sequential ‹is_closed A› ‹∀ n, f (x n) ∈ A› ‹(f∘x ⟶ f p)›) end topological_space namespace topological_space namespace first_countable_topology /-- Every first-countable space is sequential. -/ instance [topological_space α] [first_countable_topology α] : sequential_space α := ⟨show ∀ M, sequential_closure M = closure M, from assume M, suffices closure M ⊆ sequential_closure M, from set.subset.antisymm (sequential_closure_subset_closure M) this, -- For every p ∈ closure M, we need to construct a sequence x in M that converges to p: assume (p : α) (hp : p ∈ closure M), -- Since we are in a first-countable space, there exists a monotonically decreasing -- sequence g of sets generating the neighborhood filter around p: exists.elim (mono_seq_of_has_countable_basis _ (nhds_generated_countable p)) $ assume g ⟨gmon, gbasis⟩, -- (g i) is a neighborhood of p and hence intersects M. -- Via choice we obtain the sequence x such that (x i).val ∈ g i ∩ M: have x : ∀ i, g i ∩ M, { rw mem_closure_iff_nhds at hp, intro i, apply classical.choice, rw coe_nonempty_iff_ne_empty, apply hp, rw gbasis, rw ← le_principal_iff, apply lattice.infi_le_of_le i _, apply le_refl _ }, -- It remains to show that x converges to p. Intuitively this is the case -- because x i ∈ g i, and the g i get "arbitrarily small" around p. Formally: have gssnhds : ∀ s ∈ nhds p, ∃ i, g i ⊆ s, { intro s, rw gbasis, rw mem_infi, { simp, intros i hi, use i, assumption }, { apply directed_of_mono, intros, apply principal_mono.mpr, apply gmon, assumption }, { apply_instance } }, -- For the sequence (x i) we can now show that a) it lies in M, and b) converges to p. ⟨λ i, (x i).val, by intro i; simp [(x i).property.right], begin rw tendsto_at_top', intros s nhdss, rcases gssnhds s nhdss with ⟨i, hi⟩, use i, intros j hij, apply hi, apply gmon _ _ hij, simp [(x j).property.left] end⟩⟩ end first_countable_topology end topological_space
6da47143387515223ec40e44f20e0eb8ea976166
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/elab9.lean
015c42fd965460cc6ed5e4130ff8b41c27dacc07
[ "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
394
lean
set_option pp.notation false set_option pp.implicit true set_option pp.numerals false set_option pp.binder_types true #check begin tactic.unfreeze_local_instances, exact λ (A : Type*) [has_add A] [has_zero A] (a : A) (H : a + 0 = a) [has_add A] (H : a = 0 + 0), a + a end #check begin tactic.unfreeze_local_instances, exact λ (a b : nat) (H : a > b) [has_lt nat], a < b end
4961e9eca7867bab084127de6df4e7ccce772bf4
e6b8240a90527fd55d42d0ec6649253d5d0bd414
/src/topology/metric_space/basic.lean
c2dc81f53820d708b6e0ee6c1afc01ed7ad2f3ec
[ "Apache-2.0" ]
permissive
mattearnshaw/mathlib
ac90f9fb8168aa642223bea3ffd0286b0cfde44f
d8dc1445cf8a8c74f8df60b9f7a1f5cf10946666
refs/heads/master
1,606,308,351,137
1,576,594,130,000
1,576,594,130,000
228,666,195
0
0
Apache-2.0
1,576,603,094,000
1,576,603,093,000
null
UTF-8
Lean
false
false
66,841
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 data.real.nnreal topology.metric_space.emetric_space topology.algebra.ordered open lattice set filter classical topological_space noncomputable theory open_locale uniformity open_locale 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 [-dist_le_zero] using not_congr (@dist_le_zero _ _ x y) @[simp] theorem abs_dist {a b : α} : abs (dist a b) = dist a b := abs_of_nonneg dist_nonneg 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 /--`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.symm, (dist_nndist _ _).symm, imp_self, nnreal.coe_zero, dist_eq_zero] theorem nndist_comm (x y : α) : nndist x y = nndist y x := by simpa [nnreal.eq_iff.symm] 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.symm, (dist_nndist _ _).symm, 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.symm, (dist_nndist _ _).symm, 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] 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] 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] 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 ≤ ε} @[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, by simp; intros h; apply le_of_lt h 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 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⟩ theorem ball_eq_empty_iff_nonpos : ε ≤ 0 ↔ ball x ε = ∅ := (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⟩).symm theorem uniformity_dist : 𝓤 α = (⨅ ε>0, principal {p:α×α | dist p.1 p.2 < ε}) := metric_space.uniformity_dist _ theorem uniformity_dist' : 𝓤 α = (⨅ε:{ε:ℝ // ε>0}, principal {p:α×α | dist p.1 p.2 < ε.val}) := by simp [infi_subtype]; exact uniformity_dist theorem mem_uniformity_dist {s : set (α×α)} : s ∈ 𝓤 α ↔ (∃ε>0, ∀{a b:α}, dist a b < ε → (a, b) ∈ s) := begin rw [uniformity_dist', mem_infi], simp [subset_def], exact assume ⟨r, hr⟩ ⟨p, hp⟩, ⟨⟨min r p, lt_min hr hp⟩, by simp [lt_min_iff, (≥)] {contextual := tt}⟩, exact ⟨⟨1, zero_lt_one⟩⟩ end theorem dist_mem_uniformity {ε:ℝ} (ε0 : 0 < ε) : {p:α×α | dist p.1 p.2 < ε} ∈ 𝓤 α := mem_uniformity_dist.2 ⟨ε, ε0, λ a b, id⟩ theorem uniform_continuous_iff [metric_space β] {f : α → β} : uniform_continuous f ↔ ∀ ε > 0, ∃ δ > 0, ∀{a b:α}, dist a b < δ → dist (f a) (f b) < ε := uniform_continuous_def.trans ⟨λ H ε ε0, mem_uniformity_dist.1 $ H _ $ dist_mem_uniformity ε0, λ H r ru, let ⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 ru, ⟨δ, δ0, hδ⟩ := H _ ε0 in mem_uniformity_dist.2 ⟨δ, δ0, λ a b h, hε (hδ h)⟩⟩ 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. -/ 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 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. -/ 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 classical, by_cases hs : s = ∅, { rw hs, exact totally_bounded_empty }, rcases exists_mem_of_ne_empty 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 protected lemma cauchy_iff {f : filter α} : cauchy f ↔ f ≠ ⊥ ∧ ∀ ε > 0, ∃ t ∈ f, ∀ x y ∈ t, dist x y < ε := cauchy_iff.trans $ and_congr iff.rfl ⟨λ H ε ε0, let ⟨t, tf, ts⟩ := H _ (dist_mem_uniformity ε0) in ⟨t, tf, λ x y xt yt, @ts (x, y) ⟨xt, yt⟩⟩, λ H r ru, let ⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 ru, ⟨t, tf, h⟩ := H ε ε0 in ⟨t, tf, λ ⟨x, y⟩ ⟨hx, hy⟩, hε (h x y hx hy)⟩⟩ theorem nhds_eq : 𝓝 x = (⨅ε:{ε:ℝ // ε>0}, principal (ball x ε.val)) := begin rw [nhds_eq_uniformity, uniformity_dist', lift'_infi], { apply congr_arg, funext ε, rw [lift'_principal], { simp [ball, dist_comm] }, { exact monotone_preimage } }, { exact ⟨⟨1, zero_lt_one⟩⟩ }, { intros, refl } end theorem mem_nhds_iff : s ∈ 𝓝 x ↔ ∃ε>0, ball x ε ⊆ s := begin rw [nhds_eq, mem_infi], { simp }, { intros y z, cases y with y hy, cases z with z hz, refine ⟨⟨min y z, lt_min hy hz⟩, _⟩, simp [ball_subset_ball, min_le_left, min_le_right, (≥)] }, { exact ⟨⟨1, zero_lt_one⟩⟩ } end theorem is_open_iff : is_open s ↔ ∀x∈s, ∃ε>0, ball x ε ⊆ s := by simp [is_open_iff_nhds, mem_nhds_iff] theorem is_open_ball : is_open (ball x ε) := is_open_iff.2 $ λ y, exists_ball_subset_ball theorem ball_mem_nhds (x : α) {ε : ℝ} (ε0 : 0 < ε) : ball x ε ∈ 𝓝 x := mem_nhds_sets is_open_ball (mem_ball_self ε0) @[nolint] theorem mem_nhds_within_iff {t : set α} : s ∈ nhds_within x t ↔ ∃ε>0, ball x ε ∩ t ⊆ s := begin rw [mem_nhds_within_iff_exists_mem_nhds_inter], split, { rintros ⟨u, hu, H⟩, rcases mem_nhds_iff.1 hu with ⟨ε, ε_pos, hε⟩, exact ⟨ε, ε_pos, subset.trans (inter_subset_inter_left _ hε) H⟩ }, { rintros ⟨ε, ε_pos, H⟩, exact ⟨ball x ε, ball_mem_nhds x ε_pos, H⟩ } end @[nolint] 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 < ε := begin split, { assume H ε ε_pos, have : ball b ε ∩ t ∈ nhds_within b t, by { rw mem_nhds_within_iff, exact ⟨ε, ε_pos, subset.refl _⟩ }, rcases mem_nhds_within_iff.1 (H this) with ⟨δ, δ_pos, hδ⟩, exact ⟨δ, δ_pos, λx xs dx, ⟨(hδ ⟨dx, xs⟩).2, (hδ ⟨dx, xs⟩).1⟩⟩ }, { assume H u hu, rcases mem_nhds_within_iff.1 hu with ⟨ε, ε_pos, hε⟩, rcases H ε ε_pos with ⟨δ, δ_pos, hδ⟩, rw [mem_map, mem_nhds_within_iff], exact ⟨δ, δ_pos, λx hx, hε ⟨(hδ hx.2 hx.1).2, (hδ hx.2 hx.1).1⟩⟩ } end @[nolint] 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 } @[nolint] theorem tendsto_nhds_nhds [metric_space β] {f : α → β} {a b} : tendsto f (𝓝 a) (𝓝 b) ↔ ∀ ε > 0, ∃ δ > 0, ∀{x:α}, dist x a < δ → dist (f x) b < ε := by { rw [← nhds_within_univ, ← nhds_within_univ, tendsto_nhds_within_nhds_within], simp } 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 exists_delta_of_continuous [metric_space β] {f : α → β} {ε : ℝ} (hf : continuous f) (hε : ε > 0) (b : α) : ∃ δ > 0, ∀a, dist a b ≤ δ → dist (f a) (f b) < ε := let ⟨δ, δ_pos, hδ⟩ := continuous_iff.1 hf b ε hε in ⟨δ / 2, half_pos δ_pos, assume a ha, hδ a $ lt_of_le_of_lt ha $ div_two_lt_of_pos δ_pos⟩ theorem tendsto_nhds {f : filter β} {u : β → α} {a : α} : tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∃ n ∈ f, ∀x ∈ n, dist (u x) a < ε := by simp only [metric.nhds_eq, tendsto_infi, subtype.forall, tendsto_principal, mem_ball]; exact forall_congr (assume ε, forall_congr (assume hε, exists_sets_subset_iff.symm)) theorem continuous_iff' [topological_space β] {f : β → α} : continuous f ↔ ∀a (ε > 0), ∃ n ∈ 𝓝 a, ∀b ∈ n, dist (f b) (f a) < ε := continuous_iff_continuous_at.trans $ forall_congr $ λ b, tendsto_nhds theorem tendsto_at_top [nonempty β] [semilattice_sup β] {u : β → α} {a : α} : tendsto u at_top (𝓝 a) ↔ ∀ε>0, ∃N, ∀n≥N, dist (u n) a < ε := by simp only [metric.nhds_eq, tendsto_infi, subtype.forall, tendsto_at_top_principal]; 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.mem_uniformity_edist {s : set (α×α)} : s ∈ 𝓤 α ↔ (∃ε>0, ∀{a b:α}, edist a b < ε → (a, b) ∈ s) := begin refine mem_uniformity_dist.trans ⟨_, _⟩; rintro ⟨ε, ε0, Hε⟩, { refine ⟨ennreal.of_real ε, _, λ a b, _⟩, { rwa [gt, ennreal.of_real_pos] }, { rw [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 protected theorem metric.uniformity_edist' : 𝓤 α = (⨅ε:{ε:ennreal // ε>0}, principal {p:α×α | edist p.1 p.2 < ε.val}) := begin ext s, rw mem_infi, { simp [metric.mem_uniformity_edist, subset_def] }, { rintro ⟨r, hr⟩ ⟨p, hp⟩, use ⟨min r p, lt_min hr hp⟩, simp [lt_min_iff, (≥)] {contextual := tt} }, { exact ⟨⟨1, ennreal.zero_lt_one⟩⟩ } end theorem uniformity_edist : 𝓤 α = (⨅ ε>0, principal {p:α×α | edist p.1 p.2 < ε}) := by simpa [infi_subtype] using @metric.uniformity_edist' α _ /-- 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 _ _).symm, 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 := 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 classical, by_cases h : 0 < ε, { ext y, by simp [edist_dist, ennreal.of_real_lt_of_real_iff h] }, { have h' : ε ≤ 0, by simpa using h, have A : ball x ε = ∅, by simpa [ball_eq_empty_iff_nonpos.symm], have B : emetric.ball x (ennreal.of_real ε) = ∅, by simp [ennreal.of_real_eq_zero.2 h', emetric.ball_eq_empty_iff], rwa [A, B] } end /-- 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 def metric_space.replace_uniformity {α} [U : uniform_space α] (m : metric_space α) (H : @uniformity _ U = @uniformity _ (metric_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 metric_space.replace_uniformity m (by rw [uniformity_edist, 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) 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 [add_neg_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 : orderable_topology ℝ := orderable_topology_of_nhds_abs $ λ x, begin simp only [show ∀ r, {b : ℝ | abs (x - b) < r} = ball x r, by simp [-sub_eq_add_neg, 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] 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) := begin apply tendsto_of_tendsto_of_tendsto_of_le_of_le (tendsto_const_nhds) g0; simp [*]; exact filter.univ_mem_sets end theorem metric.uniformity_eq_comap_nhds_zero : 𝓤 α = comap (λp:α×α, dist p.1 p.2) (𝓝 (0 : ℝ)) := begin simp only [uniformity_dist', nhds_eq, comap_infi, comap_principal], congr, funext ε, rw [principal_eq_iff_eq], ext ⟨a, b⟩, simp [real.dist_0_eq_abs] end lemma cauchy_seq_iff_tendsto_dist_at_top_0 [inhabited β] [semilattice_sup β] {u : β → α} : cauchy_seq u ↔ tendsto (λ (n : β × β), dist (u n.1) (u n.2)) at_top (𝓝 0) := by rw [cauchy_seq_iff_prod_map, metric.uniformity_eq_comap_nhds_zero, ← map_le_iff_le_comap, filter.map_map, tendsto, prod.map_def] end real section cauchy_seq variables [inhabited β] [semilattice_sup β] /-- In a metric space, Cauchy sequences are characterized by the fact that, eventually, the distance between its elements is arbitrarily small -/ theorem metric.cauchy_seq_iff {u : β → α} : cauchy_seq u ↔ ∀ε>0, ∃N, ∀m n≥N, dist (u m) (u n) < ε := begin unfold cauchy_seq, rw metric.cauchy_iff, simp only [true_and, exists_prop, filter.mem_at_top_sets, filter.at_top_ne_bot, filter.mem_map, ne.def, filter.map_eq_bot_iff, not_false_iff, set.mem_set_of_eq], split, { intros H ε εpos, rcases H ε εpos with ⟨t, ⟨N, hN⟩, ht⟩, exact ⟨N, λm n hm hn, ht _ _ (hN _ hm) (hN _ hn)⟩ }, { intros H ε εpos, rcases H (ε/2) (half_pos εpos) with ⟨N, hN⟩, existsi ball (u N) (ε/2), split, { exact ⟨N, λx hx, hN _ _ hx (le_refl N)⟩ }, { exact λx y hx hy, calc dist x y ≤ dist x (u N) + dist y (u N) : dist_triangle_right _ _ _ ... < ε/2 + ε/2 : add_lt_add hx hy ... = ε : add_halves _ } } end /-- A variation around the metric characterization of Cauchy sequences -/ theorem metric.cauchy_seq_iff' {u : β → α} : cauchy_seq u ↔ ∀ε>0, ∃N, ∀n≥N, dist (u n) (u N) < ε := begin rw metric.cauchy_seq_iff, split, { intros H ε εpos, rcases H ε εpos with ⟨N, hN⟩, exact ⟨N, λn hn, hN _ _ hn (le_refl N)⟩ }, { intros H ε εpos, rcases H (ε/2) (half_pos εpos) with ⟨N, hN⟩, exact ⟨N, λ m n hm hn, calc dist (u m) (u n) ≤ dist (u m) (u N) + dist (u n) (u N) : dist_triangle_right _ _ _ ... < ε/2 + ε/2 : add_lt_add (hN _ hm) (hN _ hn) ... = ε : add_halves _⟩ } end /-- 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) ≤ real.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, real.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 subtype.val (λ x y, subtype.eq) t theorem subtype.dist_eq {p : α → Prop} (x y : subtype p) : dist x y = dist x.1 y.1 := 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.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.symm] end, uniformity_dist := begin refine uniformity_prod.trans _, simp [uniformity_dist, 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 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)) := have tendsto (λp:α×α, dist p.1 p.2) (𝓝 (a, b)) (𝓝 (dist a b)), from continuous_iff_continuous_at.mp continuous_dist' (a, b), tendsto.comp (by rw [nhds_prod_eq] at this; exact this) (hf.prod_mk hg) lemma nhds_comap_dist (a : α) : (𝓝 (0 : ℝ)).comap (λa', dist a' a) = 𝓝 a := have h₁ : ∀ε, (λa', dist a' a) ⁻¹' ball 0 ε ⊆ ball a ε, by simp [subset_def, real.dist_0_eq_abs], have h₂ : tendsto (λa', dist a' a) (𝓝 a) (𝓝 (dist a a)), from tendsto_dist tendsto_id tendsto_const_nhds, le_antisymm (by simp [h₁, nhds_eq, infi_le_infi, principal_mono, -le_principal_iff, -le_infi_iff]) (by simpa [map_le_iff_le_comap.symm, tendsto] using h₂) 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) lemma tendsto_nndist' (a b :α) : tendsto (λp:α×α, nndist p.1 p.2) (filter.prod (𝓝 a) (𝓝 b)) (𝓝 (nndist a b)) := by rw [← nhds_prod_eq]; exact continuous_iff_continuous_at.1 continuous_nndist' _ namespace metric variables {x y z : α} {ε ε₁ ε₂ : ℝ} {s : set α} theorem is_closed_ball : is_closed (closed_ball x ε) := is_closed_le (continuous_dist continuous_id continuous_const) continuous_const /-- ε-characterization of the closure in metric spaces-/ theorem mem_closure_iff' {α : Type u} [metric_space α] {s : set α} {a : α} : a ∈ closure s ↔ ∀ε>0, ∃b ∈ s, dist a b < ε := ⟨begin intros ha ε hε, have A : ball a ε ∩ s ≠ ∅ := mem_closure_iff.1 ha _ is_open_ball (mem_ball_self hε), cases ne_empty_iff_exists_mem.1 A with b hb, simp, exact ⟨b, ⟨hb.2, by have B := hb.1; simpa [mem_ball'] using B⟩⟩ end, begin intros H, apply mem_closure_iff.2, intros o ho ao, rcases is_open_iff.1 ho a ao with ⟨ε, ⟨εpos, hε⟩⟩, rcases H ε εpos with ⟨b, ⟨bs, bdist⟩⟩, have B : b ∈ o ∩ s := ⟨hε (by simpa [dist_comm]), bs⟩, apply ne_empty_of_mem B end⟩ lemma mem_closure_range_iff {α : Type u} [metric_space α] {e : β → α} {a : α} : a ∈ closure (range e) ↔ ∀ε>0, ∃ k : β, dist a (e k) < ε := iff.intro ( assume ha ε hε, let ⟨b, ⟨hb, hab⟩⟩ := metric.mem_closure_iff'.1 ha ε hε in let ⟨k, hk⟩ := mem_range.1 hb in ⟨k, by { rw hk, exact hab }⟩ ) ( assume h, metric.mem_closure_iff'.2 (assume ε hε, let ⟨k, hk⟩ := h ε hε in ⟨e k, ⟨mem_range.2 ⟨k, rfl⟩, hk⟩⟩) ) 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) := ⟨assume ha n, mem_closure_range_iff.1 ha (1 / ((n : ℝ) + 1)) nat.one_div_pos_of_nat, assume h, mem_closure_range_iff.2 $ assume ε hε, let ⟨n, hn⟩ := exists_nat_one_div_lt hε in let ⟨k, hk⟩ := h n in ⟨k, calc dist a (e k) < 1 / ((n : ℝ) + 1) : hk ... < ε : hn⟩⟩ 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 lattice 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 : e > 0) : ∃t ⊆ s, finite t ∧ s ⊆ ⋃x∈t, ball x e := begin apply compact_elim_finite_subcover_image hs, { simp [is_open_ball] }, { intros x xs, simp, exact ⟨x, ⟨xs, by simpa⟩⟩ } end 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 compact_inter (h x R (le_refl _)) 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 inhabited_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 α) ≠ ∅ → ∃(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. -/ assume non_empty, rcases ne_empty_iff_exists_mem.1 non_empty with ⟨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 α := ⟨by_cases 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 classical, by_cases hs : (univ : set α) = ∅, { haveI : compact_space α := ⟨by rw hs; exact compact_of_finite (set.finite_empty)⟩, by apply_instance }, rcases exists_mem_of_ne_empty 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, begin classical, by_cases s = ∅, { subst s, exact ⟨0, by simp⟩ }, { rcases exists_mem_of_ne_empty h with ⟨x, hx⟩, exact H x hx } end⟩ /-- 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⟩, { classical, by_cases s = ∅, { subst s, exact ⟨0, by simp⟩ }, { rcases exists_mem_of_ne_empty 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 /-- A finite set is bounded -/ lemma bounded_of_finite {s : set α} (h : finite s) : bounded s := bounded_of_compact $ compact_of_finite h /-- 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 := (bounded_of_compact compact_univ).subset (subset_univ _) /-- 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, bounded_of_compact h⟩, begin rintro ⟨hc, hb⟩, classical, by_cases s = ∅, {simp [h, compact_empty]}, rcases exists_mem_of_ne_empty 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) := compact_image this 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 : α} /-- 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 := by simp [diam] /-- The empty set has zero diameter -/ @[simp] lemma diam_empty : diam (∅ : set α) = 0 := by simp [diam] /-- A singleton has zero diameter -/ @[simp] lemma diam_singleton : diam ({x} : set α) = 0 := by simp [diam] /-- Characterize the boundedness of a set in terms of the finiteness of its emetric.diameter. -/ lemma bounded_iff_diam_ne_top : bounded s ↔ emetric.diam s ≠ ⊤ := begin classical, by_cases hs : s = ∅, { simp [hs] }, { rcases ne_empty_iff_exists_mem.1 hs with ⟨x, hx⟩, split, { assume bs, rcases (bounded_iff_subset_ball x).1 bs with ⟨r, hr⟩, have r0 : 0 ≤ r := by simpa [closed_ball] using hr hx, have : emetric.diam s < ⊤ := calc emetric.diam s ≤ emetric.diam (emetric.closed_ball x (ennreal.of_real r)) : by rw emetric_closed_ball r0; exact emetric.diam_mono hr ... ≤ 2 * (ennreal.of_real r) : emetric.diam_closed_ball ... < ⊤ : begin apply ennreal.lt_top_iff_ne_top.2, simp [ennreal.mul_eq_top], end, exact ennreal.lt_top_iff_ne_top.1 this }, { assume ds, have : s ⊆ closed_ball x (ennreal.to_real (emetric.diam s)), { rw [← emetric_closed_ball ennreal.to_real_nonneg, ennreal.of_real_to_real ds], exact λy hy, emetric.edist_le_diam_of_mem hy hx }, exact bounded.subset this (bounded_closed_ball) }} end /-- 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_diam_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_iff_diam_ne_top.1 (bounded.subset h ht)) (bounded_iff_diam_ne_top.1 ht), exact emetric.diam_mono h end /-- 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 := begin rw [diam, dist_edist], rw ennreal.to_real_le_to_real (edist_ne_top _ _) (bounded_iff_diam_ne_top.1 h), exact emetric.edist_le_diam_of_mem hx hy end /-- If the distance between any two points in a set is bounded by some constant, this constant bounds the diameter. -/ lemma diam_le_of_forall_dist_le {d : real} (hd : d ≥ 0) (h : ∀x y ∈ s, dist x y ≤ d) : diam s ≤ d := begin have I : emetric.diam s ≤ ennreal.of_real d, { refine emetric.diam_le_of_forall_edist_le (λx y hx hy, _), rw [edist_dist], exact ennreal.of_real_le_of_real (h x y hx hy) }, have A : emetric.diam s ≠ ⊤ := ennreal.lt_top_iff_ne_top.1 (lt_of_le_of_lt I (ennreal.lt_top_iff_ne_top.2 (by simp))), rw [← ennreal.to_real_of_real hd, diam, ennreal.to_real_le_to_real A], { exact I }, { simp } 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 := have I1 : ¬(bounded (s ∪ t)) → diam (s ∪ t) ≤ diam s + dist x y + diam t := λh, calc diam (s ∪ t) = 0 + 0 + 0 : by simp [diam_eq_zero_of_unbounded h] ... ≤ diam s + dist x y + diam t : add_le_add (add_le_add diam_nonneg dist_nonneg) diam_nonneg, have I2 : (bounded (s ∪ t)) → diam (s ∪ t) ≤ diam s + dist x y + diam t := λh, begin have : bounded s := bounded.subset (subset_union_left _ _) h, have : bounded t := bounded.subset (subset_union_right _ _) h, have A : ∀a ∈ s, ∀b ∈ t, dist a b ≤ diam s + dist x y + diam t := λa ha b hb, calc dist a b ≤ dist a x + dist x y + dist y b : dist_triangle4 _ _ _ _ ... ≤ diam s + dist x y + diam t : add_le_add (add_le_add (dist_le_diam_of_mem ‹bounded s› ha xs) (le_refl _)) (dist_le_diam_of_mem ‹bounded t› yt hb), have B : ∀a b ∈ s ∪ t, dist a b ≤ diam s + dist x y + diam t := λa b ha hb, begin cases (mem_union _ _ _).1 ha with h'a h'a; cases (mem_union _ _ _).1 hb with h'b h'b, { calc dist a b ≤ diam s : dist_le_diam_of_mem ‹bounded s› h'a h'b ... = diam s + (0 + 0) : by simp ... ≤ diam s + (dist x y + diam t) : add_le_add (le_refl _) (add_le_add dist_nonneg diam_nonneg) ... = diam s + dist x y + diam t : by simp only [add_comm, eq_self_iff_true, add_left_comm] }, { exact A a h'a b h'b }, { have Z := A b h'b a h'a, rwa [dist_comm] at Z }, { calc dist a b ≤ diam t : dist_le_diam_of_mem ‹bounded t› h'a h'b ... = (0 + 0) + diam t : by simp ... ≤ (diam s + dist x y) + diam t : add_le_add (add_le_add diam_nonneg dist_nonneg) (le_refl _) } end, have C : 0 ≤ diam s + dist x y + diam t := calc 0 = 0 + 0 + 0 : by simp ... ≤ diam s + dist x y + diam t : add_le_add (add_le_add diam_nonneg dist_nonneg) diam_nonneg, exact diam_le_of_forall_dist_le C B end, classical.by_cases I2 I1 /-- 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 ≠ ∅) : diam (s ∪ t) ≤ diam s + diam t := begin rcases ne_empty_iff_exists_mem.1 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 : r ≥ 0) : diam (closed_ball x r) ≤ 2 * r := diam_le_of_forall_dist_le (mul_nonneg (by norm_num) h) $ λa b ha 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 : r ≥ 0) : 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